首页 > 解决方案 > FluentFTP EPSV 错误 425 无法打开数据连接以传输“/test.csv”

问题描述

我正在尝试使用 EPSV 连接类型通过 .NET 库 FluentFTP 上传文件,因为我在 HTTP/1.1 代理后面,并且数据和控制 FTP IP 地址不同。

不幸的是,调用 UploadFile 方法时出现以下错误: 响应:425 无法打开数据连接以传输“/test.csv”

相同的操作在具有相同代理设置的 FileZilla 客户端中有效,因此不会是网络问题。这是我的代码:

using (FtpClientProxy client = new FtpClientHttp11Proxy(new ProxyInfo() {
    Host = "prox.corp.company.com",
    Port = 80,
    Credentials = new NetworkCredential("proxyuser", "password")})) {
        client.Host = "1.123.123.123";
        client.Port = 990;
        client.Credentials = new NetworkCredential("ftpuser", "password");
        client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
        client.DataConnectionType = FtpDataConnectionType.EPSV;
        client.EncryptionMode = FtpEncryptionMode.Implicit;
        client.Connect();

        client.UploadFile(@"C:\test.csv", "/test.csv");
}

FluentFTP 日志文件和 FileZilla 客户端日志文件的比较显示了相同的操作。

FluentFTP 日志:

Command:  SIZE /test.csv
Response: 550 File not found

OpenWrite("/test.csv", Binary)
Command:  TYPE I
Response: 200 Type set to I

OpenPassiveDataStream(EPSV, "STOR /test.csv", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||40160|)
Status:   Connecting to 1.123.1.123:80 // HTTP-Proxy
HTTP/1.1 200 Connection established

Command:  STOR /test.csv
Response: 425 Can't open data connection for transfer of "/test.csv"
Status:   Disposing FtpSocketStream...

FileZilla 客户端日志:

Status: Starting upload of C:\test.csv
Command: CWD /
Response: 250 CWD successful. "/" is current directory.
Command: TYPE I
Response: 200 Type set to I
Command: EPSV
Response: 229 Entering Extended Passive Mode (|||40132|)
Command: STOR test.csv
Status: Connection with proxy established, performing handshake...
Response: Proxy reply: HTTP/1.1 200 Connection established
Response: 150 Opening data channel for file upload to server of "/test.csv"
Response: 226 Successfully transferred "/test.csv"
Status: File transfer successful, transferred 24 bytes in 1 second

标签: c#ftpfluentftp

解决方案


我遇到了同样的问题并设法使用这些设置上传文件:

ftpClient.SslProtocols = SslProtocols.None | SslProtocols.Tls12;
ftpClient.ValidateAnyCertificate = true;
ftpClient.DataConnectionEncryption = false;

我认为这里的关键是 DataConnectionEncryption。


推荐阅读