" 425无法打开数据连接"将文件从Azure网站上传到FTP时

时间:2016-07-31 03:55:26

标签: azure ftp azure-web-sites

我想将Azure Web App创建的文件传输到Azure网络外部的FTP服务器。我得到的只是FTP上的0字节文件和" 425无法在Web应用程序上打开数据连接" 错误。

Azure Web App或FTP服务器上是否缺少某个设置?我本地IIS Express上的相同Web应用程序运行正常。 Web App使用ASP .NET MVC 5.

编辑1:

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

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();

Acording to the MSDN被动模式是默认模式。

编辑2:

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

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:

另一次尝试:

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()

2 个答案:

答案 0 :(得分:1)

&#34;无法打开数据连接&#34; 是FileZilla FTP服务器发出的消息,当它无法打开数据连接进行传输时。

当客户端在NAT或防火墙后面使用主动FTP模式并将其内部IP地址报告给服务器时,通常会发生什么,而不知道服务器无法返回到该IP地址。

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

请参阅我的article on FTP connection modes以了解主动和被动模式的含义,以及现在每个人使用被动模式的原因。

答案 1 :(得分:0)

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

相关问题