首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将文件从Azure网站上传到FTP时"425不能打开数据连接“

问将文件从Azure网站上传到FTP时"425不能打开数据连接“
EN

Stack Overflow用户
提问于 2016-07-31 03:55:26
回答 2查看 3.7K关注 0票数 0

我希望将我的Azure Web应用程序创建的文件传输到Azure网络之外的FTP服务器。我得到的只是FTP上的一个0字节文件和Web应用程序上的"425不能打开数据连接“错误。

在Azure Web应用程序或FTP服务器上是否缺少设置?本地IIS Express上的相同Web应用程序运行良好。Web使用ASP .NET MVC 5。

编辑1:

这是我用来发送文件的代码:

代码语言:javascript
复制
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ftp + fileName);
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Credentials = new NetworkCredential(uid, pwd);
ftpRequest.ContentLength = fileBytes.Length;

Stream requestStream = ftpRequest.GetRequestStream();
requestStream.Write(fileBytes, 0, fileBytes.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
var status = response.StatusCode;
response.Close();

根据MSDN被动模式是默认模式。

编辑2:

启用服务器日志--这是输出:

代码语言:javascript
复制
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Created connection from <origin_ip> to <destination_ip>.
System.Net Information: 0 : [60572] Associating FtpWebRequest#23597360 with FtpControlStream#51898079
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [220 Microsoft FTP Service]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [USER <user>]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [331 Password required for <user>.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PASS *]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [230 User <user> logged in.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [501 option not supported]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PWD]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [257 "/" is current directory.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [TYPE I]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [200 Type set to I.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PASV]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [227 Entering Passive Mode (12,106,237,74,4,255).]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [STOR <file>]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [425 Can't open data connection.]
System.Net Information: 0 : [60572] FtpWebRequest#23597360::(Releasing FTP connection#51898079.)
System.Net Error: 0 : [60572] Exception in FtpWebRequest#23597360::GetRequestStream - The remote server returned an error: (425) Can't open data connection..
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetRequestStream()

编辑3:

另一次尝试:

代码语言:javascript
复制
System.Net Information: 0 : [58636] FtpWebRequest#9144495::.ctor(<ftp_address_and_file>)
System.Net Information: 0 : [58636] FtpWebRequest#9144495::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Created connection from <origin_ip> to <destination_ip>.
System.Net Information: 0 : [58636] Associating FtpWebRequest#9144495 with FtpControlStream#57089836
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [220 Microsoft FTP Service]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [USER <user>]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [331 Password required for <user>.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PASS *]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [230 User <user> logged in.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [501 option not supported]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PWD]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [257 "/" is current directory.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [TYPE I]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [200 Type set to I.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PASV]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [227 Entering Passive Mode (12,106,237,74,5,4).]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [STOR <file>]
System.Net Information: 0 : [58636] FtpWebRequest#9144495::(Releasing FTP connection#57089836.)
System.Net Error: 0 : [58636] Exception in FtpWebRequest#9144495::GetRequestStream - The operation has timed out..
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetRequestStream()
EN

回答 2

Stack Overflow用户

发布于 2016-07-31 06:58:03

“无法打开数据连接”是由FileZilla FTP服务器发出的消息,当它无法打开数据连接以进行传输时。

通常情况下,当客户端在NAT或防火墙之后使用活动FTP模式并向服务器报告其内部IP地址时,不知道服务器无法返回到该IP地址。

最简单(而且通常是正确的)解决方案是使用FTP被动模式,而不是主动模式。

看看我的关于FTP连接模式的文章,了解主动模式和被动模式意味着什么,以及为什么现在每个人都使用被动模式。

票数 1
EN

Stack Overflow用户

发布于 2016-07-31 05:53:52

尝试在客户端切换到FTP被动模式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38680616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档