{"id":1512,"date":"2010-11-06T18:29:29","date_gmt":"2010-11-06T16:29:29","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1512"},"modified":"2012-06-03T15:31:14","modified_gmt":"2012-06-03T13:31:14","slug":"use-ssl-with-ftp-ftps","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/use-ssl-with-ftp-ftps","title":{"rendered":"Use SSL with FTP (FTPS)"},"content":{"rendered":"<p>Using FTPS (FTP protocol over secure SSL channel is easy with Ftp.dll <a href=\"\/ftp\">.NET FTPS component<\/a>. The only difference compared to the FTP protocol is that you need to use ConnectSSL method instead of regular Connect:<\/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.ConnectSSL(&quot;ftp.example.org&quot;);\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.ConnectSSL(&quot;ftp.example.org&quot;)\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 990, you need to use overloaded version of <em>ConnectSSL<\/em><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C# version\r\n\r\nclient.ConnectSSL(&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.ConnectSSL(&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.ConnectSSL(&quot;ftp.example.org&quot;);\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.ConnectSSL(&quot;ftp.example.org&quot;)\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>You can <a href=\"\/ftp\">download Ftp.dll FTP\/FTPS client for .NET here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using FTPS (FTP protocol over secure SSL channel is easy with Ftp.dll .NET FTPS component. The only difference compared to the FTP protocol is that you need to use ConnectSSL method instead of regular Connect: \/\/ C# version using (Ftp client = new Ftp()) { client.ConnectSSL(&quot;ftp.example.org&quot;); client.Login(&quot;username&quot;, &quot;password&quot;); foreach (FtpItem item in client.GetList()) { if [&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,57],"class_list":["post-1512","post","type-post","status-publish","format-standard","hentry","category-ftp-dll","tag-c","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\/1512"}],"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=1512"}],"version-history":[{"count":5,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1512\/revisions"}],"predecessor-version":[{"id":3075,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1512\/revisions\/3075"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}