FtpWebRequest“根据验证过程,远程证书无效". [英] FtpWebRequest "The remote certificate is invalid according to the validation procedure"

查看:98
本文介绍了FtpWebRequest“根据验证过程,远程证书无效".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET客户端应用程序,尝试将文件通过ftp传输到具有自签名SSL证书的ftp站点.该ftp站点正在Windows 7 Enterprise IIS 7上运行.我收到以下错误消息:根据验证过程,远程证书无效."

I have a .NET client application that tries to ftp over a file to an ftp site which has a Self signed SSL certificate. This ftp site is running on Windows 7 Enterprise, IIS 7. I am getting the following error: "The remote certificate is invalid according to the validation procedure".

我尝试将证书安装在受信任的根证书中,但这仍然无法正常工作.

I have tried installing the certificate in the trusted root certificates but that still does not work.

我已经在代码中使用了委托回调,这里提到了一些帖子-它可以工作.但是我不想在生产代码中使用它.

I have used the delegate call back in the code that is mentioned some of the posts here - it works. But I do not want to use that in my production code.

在生产中,我们的一些客户也在使用自签名证书.

Also in production some of our customers are using self signed certificates.

关于如何解决此问题的任何想法?

Any ideas on how to fix this issue?

推荐答案

您必须覆盖证书检查,以便始终将其视为合格.这不会阻止该频道继续受SSL保护.

You have to overwrite the certificate checks so that they will always be considered good. That won't prevent the channel to remain SSL protected.

Uri target = new Uri("ftp://yourUri");
string fileName = @"fullPathOfYourFile";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("user", "password");
request.EnableSsl = true;

//overwrite the certificate checks
ServicePointManager.ServerCertificateValidationCallback = 
                      (s, certificate, chain, sslPolicyErrors) => true;

// Copy the contents of the file to the request stream
//....

这篇关于FtpWebRequest“根据验证过程,远程证书无效".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆