mos*_*osu 5 c# ftp ssl ftpwebrequest
我实现了我的自定义FTP类来处理我正在支付的托管服务器.我使用FTP来备份,恢复和更新我的应用程序.我现在正处于想要让ssl投入生产的那一刻.我问我的托管公司他们是否支持ssl协议,他们说他们这样做.
所以我在Microsoft MSDN教程之后将我的方法修改为:
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(m_ftpAddress.Trim()));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(m_ftpUsername, m_ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
X509Certificate cert = new X509Certificate(path to a certificate created with makecert.exe);
reqFTP.ClientCertificates.Add(cert);
reqFTP.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
reqFTP.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Identification;
reqFTP.EnableSsl = true;
Run Code Online (Sandbox Code Playgroud)
现在,MSDN说如果服务器支持ssl协议,当被问到AUTH TLS时,它不会抛出异常.这可以在跟踪日志中看到.所以我认为这不是服务器问题.
在身份验证阶段之后,服务器返回a
System.Net信息:0:[0216] FtpControlStream#41622463 - 接收响应[227进入被动模式(IP和端口号).]
触发错误的消息:
System.Net错误:0:[0216] FtpWebRequest中的异常#12547953 :: GetResponse - 远程服务器返回错误:227进入被动模式(IP和端口号).
我试过设置
reqFTP.UsePassive = true;
Run Code Online (Sandbox Code Playgroud)
属性为false然后我收到此错误:
System.Net信息:0:[2692] FtpControlStream#4878312 - 收到回复[500 Illegal PORT command]
当然,如果没有将EnableSLL属性设置为true,一切都可以正常工作.
有没有人对此有任何想法?
编辑:我将代码修改为休耕:
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(m_ftpAddress.Trim()));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(m_ftpUsername, m_ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
ServicePointManager.ServerCertificateValidationCallback = new
System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
reqFTP.ClientCertificates.Add(cert);
reqFTP.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
reqFTP.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Identification
reqFTP.EnableSsl = true;
Run Code Online (Sandbox Code Playgroud)
将ValidateServerCertificate始终返回真.在此修改之后,效果为无.
我不明白:
有人可以解释我的工作原理吗?
编辑:在与托管公司交换了许多电子邮件之后,结果证明他们的FTP软件存在问题,而且代码没有问题.