我实现了我的自定义FTP类,以使用我正在付费的托管服务器。我使用FTP备份、还原和更新我的应用程序。现在,我希望使ssl能够将其应用到生产中。我问我的托管公司是否支持ssl协议,他们说他们支持。
因此,在Microsoft教程之后,我修改了我的方法如下:
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;现在,MSDN说,如果服务器支持ssl协议,那么当使用AUTH询问时,它不会抛出异常。这可以在跟踪日志中看到。所以我想这不是服务器问题。
在身份验证阶段之后,服务器返回
System.Net信息:0: 0216 FtpControlStream#41622463 -接收到的响应227进入被动模式( IP和端口号)。
触发错误的消息:
System.Net错误:0: 0216 FtpWebRequest#12547953::GetResponse中的异常-远程服务器返回一个错误: 227输入被动模式( IP和端口号)。
我试着设置
reqFTP.UsePassive = true;属性为false,然后得到以下错误:
System.Net信息:0: 2692 FtpControlStream#4878312 -收到响应500非法端口命令
当然,如果没有将EnableSLL属性设置为true,一切都可以正常工作。
有人知道这件事吗?
编辑:i将代码修改为fallows:
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;ValidateServerCertificate总是返回真。经过这一修改后,效果为零。
我不明白:
。
有人能解释一下我的工作原理吗?
编辑:在与托管公司交换了很多电子邮件后,发现他们的FTP软件有问题,代码也没有问题。
发布于 2010-11-12 03:30:16
您是否检查了您的主机是在使用FTPS还是SFTP?
它们是不同的协议,您的主机可能以为您说的是错误的。
https://stackoverflow.com/questions/1608038
复制相似问题