惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
博客园 - 司徒正美
L
LangChain Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Troy Hunt's Blog
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Scott Helme
Scott Helme
Recent Announcements
Recent Announcements
S
Secure Thoughts
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
Hacker News - Newest:
Hacker News - Newest: "LLM"
雷峰网
雷峰网
Attack and Defense Labs
Attack and Defense Labs
A
About on SuperTechFans
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
V2EX - 技术
V2EX - 技术
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
N
Netflix TechBlog - Medium
B
Blog RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
PCI Perspectives
PCI Perspectives
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hacker News: Front Page

博客园 - 阿龍

FW:Software Testing What is the difference between modified duration, effective duration and duration? Netezza External Tables --How to use local files in external table How to push master to QA branch in GIT FTPS Firewall Query performance optimization of Vertica (Forward)5 Public Speaking Tips That'll Prepare You for Any Interview Change - Why we need coding standards (转)测试用例编写规范 (转)测试用例模板(Test Case Template) (转)Facebook如何提高软件质量? 敏捷问题小结 (转)RACI模型(RACI Model) (转)Part 2 - Basic of mocking with Moq (转)MongoDB——安装篇(windows) (转)MongoDB 增加用户 删除用户 修改用户 读写权限 只读权限, (转)MongoDB设置访问权限、设置用户 赎回收益率(Yield to Call,YTC) YTC, YTM, YTW
(转)The remote certificate is invalid according to the validation procedure
阿龍 · 2013-07-15 · via 博客园 - 阿龍

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 FTP and FTPS .NET component.

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# version

using (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 download Ftp.dll FTP/FTPS component for .NET here.