得到421错误

时间:2016-05-06 14:15:29

标签: c# ftp ftp-client

我试图从公共ftp服务器下载文件。这是我的c#源代码:

        FtpWebRequest request = FtpWebRequest.Create(new Uri("ftp://ftp.exotic-guild.de/test.exe")) as FtpWebRequest;


        request.Credentials = new NetworkCredential("anonymous@exotic-guild.de", "");
        request.UsePassive = true;
        request.UseBinary = true;
        request.KeepAlive = true;
        request.Method = WebRequestMethods.Ftp.DownloadFile;
        FtpWebResponse response = request.GetResponse() as FtpWebResponse;
        System.IO.Stream responseStream = response.GetResponseStream();

        responseStream.Close();
        response.Close(); //Closes the connection to the server

以下是来自public_ftp服务器的文档的链接:wolkenbauer anonymus ftp documentation

1 个答案:

答案 0 :(得分:1)

使用ftp.exe ftp.exotic-guild.de响应是:

  

421抱歉,此服务器不接受明文会话和弱密码。   请使用SSL / TLS安全机制重新连接。   连接由远程主机关闭。

添加:

request.EnableSsl = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

第二行绕过证书验证,因为提供的证书由于某种原因无效(您可能想调查)。

  

根据验证程序

,远程证书无效