{"id":1569,"date":"2010-11-07T15:36:33","date_gmt":"2010-11-07T13:36:33","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1569"},"modified":"2022-10-23T19:58:52","modified_gmt":"2022-10-23T17:58:52","slug":"the-remote-certificate-is-invalid-according-to-the-validation-procedure-ftp","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/the-remote-certificate-is-invalid-according-to-the-validation-procedure-ftp","title":{"rendered":"The remote certificate is invalid according to the validation procedure"},"content":{"rendered":"\n<p>If you get &#8220;The remote certificate is invalid according to the validation procedure&#8221; exception while trying to establish SSL connection, most likely your server certificate is <strong>self-signed<\/strong> or you used <strong>incorrect host name<\/strong> 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).<\/p>\n\n\n\n<p>Good news is that you can <strong>accept self-signed certificates<\/strong> using Ftp.dll <a href=\"\/ftp\">FTP and FTPS .NET component<\/a>.<\/p>\n\n\n\n<p>First you need to subscribe to <em>ServerCertificateValidate <\/em>event.<\/p>\n\n\n\n<p>Then you need to create <em>Validate<\/em>method that validates the certificate (ignores certificate chain and name mismatch errors).<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C# version\n\nusing (Ftp client = new Ftp())\n{\n    \/\/ Use custom certificate validation:\n    client.ServerCertificateValidate +=\n        new ServerCertificateValidateEventHandler(Validate);\n\n    \/\/ Minimalistic version to accept any certificate:\n    \/\/ \n    \/\/client.ServerCertificateValidate +=\n    \/\/    (sender, e) =&gt; { e.IsValid = true; };\n    \/\/ \n\n    client.ConnectSSL(\"ftp.example.org\");\n    client.Login(\"username\", \"password\");\n\n    foreach (FtpItem item in client.GetList())\n    {\n        if (item.IsFolder == true)\n            Console.WriteLine(\"&#x5B;{0}]\", item.Name);\n        else\n            Console.WriteLine\"{0}\", item.Name);\n    }\n    client.Close();\n}\n\nprivate static void Validate(\n    object sender,\n    ServerCertificateValidateEventArgs e)\n{\n    const SslPolicyErrors ignoredErrors =\n        \/\/ self-signed\n        SslPolicyErrors.RemoteCertificateChainErrors\n        \/\/ name mismatch\n        |  SslPolicyErrors.RemoteCertificateNameMismatch;  \n\n    if ((e.SslPolicyErrors &amp; ~ignoredErrors) \n        == SslPolicyErrors.None)\n    {\n        e.IsValid = true;\n        return;\n    }\n    e.IsValid = false;\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n' VB.NET version\n\nUsing client As New Ftp()\n    ' Use custom certificate validation:\n    AddHandler client.ServerCertificateValidate, AddressOf Validate\n\n    client.ConnectSSL(\"ftp.example.org\")\n    client.Login(\"username\", \"password\")\n\n    For Each item As FtpItem In client.GetList()\n        If item.IsFolder = True Then\n            Console.WriteLine(\"&#x5B;{0}]\";, item.Name)\n        Else\n            Console.WriteLine(\"{0}\", item.Name)\n        End If\n    Next\n    client.Close()\nEnd Using\n\nPrivate Sub Validate( _\n    ByVal sender As Object, _\n    ByVal e As ServerCertificateValidateEventArgs)\n\n    Const ignoredErrors As SslPolicyErrors = _\n        ' self-signed\n        SslPolicyErrors.RemoteCertificateChainErrors _    \n        ' name mismatch\n        Or SslPolicyErrors.RemoteCertificateNameMismatch        \n\n    If (e.SslPolicyErrors And Not ignoredErrors) = SslPolicyErrors.None Then\n        e.IsValid = True\n        Return\n    End If\n    e.IsValid = False\nEnd Sub\n<\/pre><\/div>\n\n\n<p>You can <a href=\"\/ftp\">download Ftp.dll FTP\/FTPS component for .NET here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you get &#8220;The remote certificate is invalid according to the validation procedure&#8221; exception while trying to establish SSL connection, most likely your 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[15,128,22,80,24,57],"class_list":["post-1569","post","type-post","status-publish","format-standard","hentry","category-ftp-dll","tag-c","tag-certificate","tag-ftp","tag-ftp-component","tag-ftps","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1569"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=1569"}],"version-history":[{"count":13,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1569\/revisions"}],"predecessor-version":[{"id":6385,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1569\/revisions\/6385"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}