当前位置: 首页 > 知识库问答 >
问题:

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

钱均
2023-03-14

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

Azure Web应用程序或FTP服务器上是否缺少设置?在我的本地IIS Express上使用相同的Web应用程序可以正常工作。该Web应用程序使用ASP。NETMVC5。

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

根据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个答案

钱旻
2023-03-14

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

澹台景辉
2023-03-14

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

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

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

请参阅我关于FTP连接模式的文章,了解主动模式和被动模式的含义,以及为什么现在每个人都使用被动模式。

 类似资料:
  • 我正在使用Teamcity在FTP中部署我的Web应用程序。在周一之前,部署工作一直很顺利。现在它不再工作了。我没有对Teamcity做任何更改。问题:FTP传输正常启动。一些文件被传输。然后它会中断FTP错误:“425无法打开数据连接”。FTP部署在我的所有其他Web应用程序上都可以正常工作。关于这个问题你能给我一个提示吗?teamcity步骤配置 日志: [13:57:10]i:[步骤1/1]

  • 我用这个上传一些文件。如果我在本地连接中,它可以工作,但如果我使用外部连接,我会收到以下消息:

  • 我需要编写一个连接到FTP服务器的应用程序。此FTP服务器不允许被动模式连接。我可以使用Filezilla连接到FTP服务器。 我开发了一个C#WCF服务,它使用FTPWebRequest类连接到此FTP服务器。以下是FTPWebRequest对象的基本设置: 当我从Visual Studio(Ctrl F5)运行WCF服务时,它连接到FTP服务器并下载所需的文件,没有任何问题 但是,当我在本地I

  • 我正在使用Teamcity在FTP中部署我的Web应用程序。在周一之前,部署工作非常顺利。现在它不再起作用了。我没有对团队城做任何修改。问题:FTP传输正常启动。有些文件被转移。然后它以FTP错误中断:“425无法打开数据连接”。FTP部署在我的所有其他Web应用程序上都运行良好。你能给我一个关于这个问题的提示吗?TeamCity step配置 日志: [13:57:10]I:[步骤1/1]<25

  • 我正在尝试用Java从头开始创建一个FTP客户端。 我使用Filezilla作为服务器,可以连接到某个点。我的意思是,我有命令端口工作,但无论我搜索多少,我都无法连接数据端口。 我找过的所有网站都说问题与防火墙和/或路由器有关,但是,当我尝试使用Filezilla客户端连接到服务器时,一切都很顺利。 到目前为止我所拥有的: 将我登录到服务器并断开连接。为了解决这个问题,我在线程中添加了一个infi

  • 我试图连接到网站在使用filezilla赢得Azure。它连接正常几分钟,我能够上传文件。但是后来它停止了工作。我收到这个消息: 响应:257"/"是当前目录。命令:I型响应:200型设置为I型。命令:PASV响应:227进入被动模式(137,117,88,16,40,32)。命令:列表响应:150打开二进制模式数据连接。响应:550网络连接被本地系统中止。错误:检索目录列表失败 我尝试过将传输模