{"id":1574,"date":"2010-11-07T15:41:08","date_gmt":"2010-11-07T13:41:08","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1574"},"modified":"2012-06-03T15:38:12","modified_gmt":"2012-06-03T13:38:12","slug":"the-handshake-failed-due-to-an-unexpected-packet-format-ftp","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/the-handshake-failed-due-to-an-unexpected-packet-format-ftp","title":{"rendered":"The handshake failed due to an unexpected packet format"},"content":{"rendered":"<p>Most likely your FTP server requires <strong>explicit<\/strong> SSL. So first try to connect without SSL:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nclient.Connect(&quot;ftp.example.org&quot;);\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nclient.Connect(&quot;ftp.example.org&quot;)\r\n<\/pre>\n<p>Then, before logging-in, <strong>start explicit SSL negotiation<\/strong>:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nclient.AuthSSL();\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nclient.AuthSSL()\r\n<\/pre>\n<p>Now,<strong> your connection is secured<\/strong>.<\/p>\n<p>Remember that you can ignore<strong> SSL certificate errors<\/strong> using <em>ServerCertificateValidate <\/em>event:<\/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.AuthSSL();\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>You can <a href=\"\/ftp\">download Ftp.dll FTP\/FTPS client for .NET here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most likely your FTP server requires explicit SSL. So first try to connect without SSL: \/\/ C# client.Connect(&quot;ftp.example.org&quot;); &#8216; VB.NET client.Connect(&quot;ftp.example.org&quot;) Then, before logging-in, start explicit SSL negotiation: \/\/ C# client.AuthSSL(); &#8216; VB.NET client.AuthSSL() Now, your connection is secured. Remember that you can ignore SSL certificate errors using ServerCertificateValidate event: \/\/ C# version using (Ftp [&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-1574","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\/1574"}],"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=1574"}],"version-history":[{"count":5,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1574\/revisions"}],"predecessor-version":[{"id":3086,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1574\/revisions\/3086"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}