C# FtpWebRequest 访问 FileZilla 出现错误


错误信息

425 Can't open data connection for transfer of ""

Request 类

internal class MyWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            FtpWebRequest req = (FtpWebRequest) base.GetWebRequest(address);
            req.Timeout = 115000;
            req.ReadWriteTimeout = 115000;
            req.KeepAlive = true;
            req.UsePassive = true;// change false to true to avoid error code 425 by lance 2016-03-15

            return req;
        }
    }
    #endregion

解答

Port 20 is used as a source port for data connections in active mode (the on you use here) if the server listens on the default port 21. According to RFC959, 3.2 the default source port of the server for data connections is L-1, e.g. if L is 30 like in your case the source port should be 29 and no longer 20 so you have to allow connections from port 29.

最好先检查服务端的设置,然后检查本地代码访问方式

知识共享许可协议
《C# FtpWebRequest 访问 FileZilla 出现错误》 常伟华 创作。
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议 | 3.0 中国大陆许可协议进行许可。

站内公告

A PHP Error was encountered

Severity: Core Warning

Message: PHP Startup: zip: Unable to initialize module Module compiled with module API=20060613 PHP compiled with module API=20090626 These options need to match

Filename: Unknown

Line Number: 0

Backtrace: