首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FtpWebRequest与EnableSSL

FtpWebRequest与EnableSSL
EN

Stack Overflow用户
提问于 2009-10-22 15:29:27
回答 1查看 11.3K关注 0票数 5

我实现了我的自定义FTP类,以使用我正在付费的托管服务器。我使用FTP备份、还原和更新我的应用程序。现在,我希望使ssl能够将其应用到生产中。我问我的托管公司是否支持ssl协议,他们说他们支持。

因此,在Microsoft教程之后,我修改了我的方法如下:

代码语言:javascript
复制
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和端口号)。

我试着设置

代码语言:javascript
复制
reqFTP.UsePassive = true;

属性为false,然后得到以下错误:

System.Net信息:0: 2692 FtpControlStream#4878312 -收到响应500非法端口命令

当然,如果没有将EnableSLL属性设置为true,一切都可以正常工作。

有人知道这件事吗?

编辑:i将代码修改为fallows:

代码语言:javascript
复制
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总是返回。经过这一修改后,效果为零。

我不明白:

  • 在这个时刻,应用程序正在使用服务器证书,对吗?
  • ,在修改之前也使用了In ?

有人能解释一下我的工作原理吗?

编辑:在与托管公司交换了很多电子邮件后,发现他们的FTP软件有问题,代码也没有问题。

EN

回答 1

Stack Overflow用户

发布于 2010-11-12 03:30:16

您是否检查了您的主机是在使用FTPS还是SFTP?

它们是不同的协议,您的主机可能以为您说的是错误的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1608038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档