{"id":1523,"date":"2010-11-07T14:18:24","date_gmt":"2010-11-07T12:18:24","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1523"},"modified":"2017-07-12T10:49:03","modified_gmt":"2017-07-12T08:49:03","slug":"use-ssl-with-ftp-explicit","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/use-ssl-with-ftp-explicit","title":{"rendered":"Use SSL with FTP (Explicit)"},"content":{"rendered":"<p>Explicit SSL uses the same port that regular FTP (21).<\/p>\n<p>After regular connection, client <strong>explicitly asks the server to secure the connection<\/strong>. &#8220;AUTH TLS&#8221; command is used to do that.<br \/>\nAs the SSL\/TLS protocols self-negotiate their levels, there is no need to distinguish between SSL and TLS.<\/p>\n<p>You should use <em>AuthTLS<\/em> method to enable TLS\/SSL for both data channel and control channel:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing (Ftp client = new Ftp())\r\n{\r\n    client.Connect(&quot;ftp.example.org&quot;);\r\n\r\n    client.AuthTLS();\r\n\r\n    client.Login(&quot;username&quot;, &quot;password&quot;);\r\n\r\n    foreach (FtpItem item in client.GetList())\r\n    {\r\n        if (item.IsFolder == true)\r\n            Console.WriteLine(&quot;&#x5B;{0}]&quot;, item.Name);\r\n        else\r\n            Console.WriteLine(&quot;{0}&quot;, item.Name);\r\n    }\r\n    client.Close();\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nUsing client As New Ftp()\r\n\r\n    client.Connect(&quot;ftp.example.org&quot;)\r\n\r\n    client.AuthTLS()\r\n\r\n    client.Login(&quot;username&quot;, &quot;password&quot;)\r\n\r\n    For Each item As FtpItem In client.GetList()\r\n        If item.IsFolder = True Then\r\n            Console.WriteLine(&quot;&#x5B;{0}]&quot;, item.Name)\r\n        Else\r\n            Console.WriteLine(&quot;{0}&quot;, item.Name)\r\n        End If\r\n    Next\r\n    client.Close()\r\nEnd Using\r\n\r\n<\/pre>\n<p>If your FTP server is using <strong>other port<\/strong> than standard 21, you need to use overloaded version of <em>Connect<\/em><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nclient.Connect(&quot;ftp.example.org&quot;, 999);\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nclient.Connect(&quot;ftp.example.org&quot;, 999)\r\n<\/pre>\n<p>The last sample shows how to deal with <strong>self-signed certificates<\/strong>:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nusing (Ftp client = new Ftp())\r\n{\r\n    \/\/ Use this line to validate self-signed certificates:\r\n    client.ServerCertificateValidate += ValidateCertificate;\r\n\r\n    client.Connect(&quot;ftp.example.org&quot;);\r\n    client.AuthTLS();\r\n    client.Login(&quot;username&quot;, &quot;password&quot;);\r\n\r\n    foreach (FtpItem item in client.GetList())\r\n    {\r\n        if (item.IsFolder == true)\r\n            Console.WriteLine(&quot;&#x5B;{0}]&quot;, item.Name);\r\n        else\r\n            Console.WriteLine(&quot;{0}&quot;, item.Name);\r\n    }\r\n    client.Close();\r\n}\r\n\r\nprivate static void ValidateCertificate(\r\n    object sender,\r\n    ServerCertificateValidateEventArgs e)\r\n{\r\n    const SslPolicyErrors ignoredErrors =\r\n        SslPolicyErrors.RemoteCertificateChainErrors |\r\n        SslPolicyErrors.RemoteCertificateNameMismatch;\r\n\r\n    if ((e.SslPolicyErrors &amp; ~ignoredErrors) == SslPolicyErrors.None)\r\n    {\r\n        e.IsValid = true;\r\n        return;\r\n    }\r\n    e.IsValid = false;\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET version\r\n\r\nUsing client As New Ftp()\r\n    ' Use this line to validate self-signed certificates:\r\n    AddHandler client.ServerCertificateValidate, AddressOf ValidateCerificate\r\n\r\n    client.Connect(&quot;ftp.example.org&quot;)\r\n    client.AuthSSL()\r\n    client.Login(&quot;username&quot;, &quot;password&quot;)\r\n\r\n    For Each item As FtpItem In client.GetList()\r\n        If item.IsFolder = True Then\r\n            Console.WriteLine(&quot;&#x5B;{0}]&quot;, item.Name)\r\n        Else\r\n            Console.WriteLine(&quot;{0}&quot;, item.Name)\r\n        End If\r\n    Next\r\n    client.Close()\r\nEnd Using\r\n\r\nPrivate Sub ValidateCerificate( _\r\n    ByVal sender As Object, _\r\n    ByVal e As ServerCertificateValidateEventArgs)\r\n\r\n    Const ignoredErrors As SslPolicyErrors = _\r\n        SslPolicyErrors.RemoteCertificateChainErrors Or _\r\n        SslPolicyErrors.RemoteCertificateNameMismatch\r\n\r\n    If (e.SslPolicyErrors And Not ignoredErrors) = SslPolicyErrors.None Then\r\n        e.IsValid = True\r\n        Return\r\n    End If\r\n    e.IsValid = False\r\nEnd Sub\r\n<\/pre>\n<p>Here you can download Ftp.dll: <a href=\"\/ftp\">.NET FTP\/FTPS component<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explicit SSL uses the same port that regular FTP (21). After regular connection, client explicitly asks the server to secure the connection. &#8220;AUTH TLS&#8221; command is used to do that. As the SSL\/TLS protocols self-negotiate their levels, there is no need to distinguish between SSL and TLS. You should use AuthTLS method to enable TLS\/SSL [&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,22,80,24,53,83,57],"class_list":["post-1523","post","type-post","status-publish","format-standard","hentry","category-ftp-dll","tag-c","tag-ftp","tag-ftp-component","tag-ftps","tag-ssl","tag-tls","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1523"}],"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=1523"}],"version-history":[{"count":10,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"predecessor-version":[{"id":5357,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1523\/revisions\/5357"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}