博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转)The remote certificate is invalid according to the validation procedure
阅读量:5332 次
发布时间:2019-06-14

本文共 1828 字,大约阅读时间需要 6 分钟。

If you get “The remote certificate is invalid according to the validation procedure” exception while trying to establish SSL connection, most likely your’s server certificate is self-signed or you used incorrect host name to connect (Host name must match the name on certificate, for example ftp.example.com and example.com may point to the same server, but certificate is issued only to ftp.example.com and this is the address you should use).

Good news is that you can accept self-signed certificates using Ftp.dll .

First you need to subscribe to ServerCertificateValidate event.

Then you need to create ValidateCertificate method that validates the certificate (ignores certificate chain and name mismatch errors).

// C# versionusing (Ftp client = new Ftp()){    // we will use custom validation    client.ServerCertificateValidate +=        new ServerCertificateValidateEventHandler(Validate);    // Minimalistic version to accept any certificate:    //client.ServerCertificateValidate +=     //    (sender, e) => { e.IsValid = true; };    client.ConnectSSL("ftp.example.org");    client.Login("username", "password");    foreach (FtpItem item in client.GetList())    {        if (item.IsFolder == true)            Console.WriteLine("[{0}]", item.Name);        else            Console.WriteLine"{0}", item.Name);    }    client.Close();}private static void ValidateCertificate(    object sender,    ServerCertificateValidateEventArgs e){    const SslPolicyErrors ignoredErrors =        SslPolicyErrors.RemoteCertificateChainErrors |  // self-signed        SslPolicyErrors.RemoteCertificateNameMismatch;  // name mismatch    if ((e.SslPolicyErrors & ~ignoredErrors) == SslPolicyErrors.None)    {        e.IsValid = true;        return;    }    e.IsValid = false;}

You can .

 

转载于:https://www.cnblogs.com/s021368/p/3190481.html

你可能感兴趣的文章
R12 付款过程请求-功能和技术信息 (文档 ID 1537521.1)
查看>>
洛谷 4364 [九省联考2018]IIIDX
查看>>
洛谷 3870 [TJOI2009]开关
查看>>
【牛客-16643】统计数字(简单排序)
查看>>
www.aaa.com/index.html跳转www.aaa.com设置
查看>>
ssdb binlog机制 存疑
查看>>
Vue 2.0 组件库总结
查看>>
HDU5033 Building(单调栈)
查看>>
Kafka 安装配置 及 简单实验记录
查看>>
想成为程序猿?28个程序员专供在线学习网站(转)
查看>>
font-style: oblique文字斜体,display:inline-block显示间隙
查看>>
css设置滚动条并显示或隐藏
查看>>
【leetcode❤python】13. Roman to Integer
查看>>
常用关于 JavaScript 中的跨域访问方法
查看>>
织梦万能调用LOOP标签!
查看>>
Microsoft 官网 socket异步
查看>>
asp.net MVC helper 和自定义函数@functions小结
查看>>
L1-Day34
查看>>
Linux主机在LNMP环境中同时运行多个PHP版本
查看>>
玩转Xcode之修改系统生成的注释模板
查看>>