{"id":1527,"date":"2010-11-07T14:37:47","date_gmt":"2010-11-07T12:37:47","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1527"},"modified":"2013-06-26T10:37:38","modified_gmt":"2013-06-26T08:37:38","slug":"issue-a-custom-command-to-ftp-server","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/issue-a-custom-command-to-ftp-server","title":{"rendered":"Issue a custom command to FTP server"},"content":{"rendered":"<p>This article describes how to issue a custom command to FTP server using Ftp.dll &#8211; <a href=\"\/ftp\">.NET FTP and FTPS library<\/a>.<\/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    client.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    FtpResponse response = client.SendCommand(&quot;HELP&quot;);\r\n\r\n    Console.WriteLine(response.Message);\r\n    foreach (string line in response.Lines)\r\n        Console.WriteLine(line);\r\n\r\n    client.Close();\r\n}\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\tclient.Connect(&quot;ftp.example.org&quot;)\r\n\tclient.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n\tDim response As FtpResponse = client.SendCommand(&quot;HELP&quot;)\r\n\r\n\tConsole.WriteLine(response.Message)\r\n\tFor Each line As String In response.Lines\r\n\t\tConsole.WriteLine(line)\r\n\tNext\r\n\r\n\tclient.Close()\r\nEnd Using\r\n\r\n<\/pre>\n<p>The abowe code producess following output:<\/p>\n<p><code><br \/>\nThe following commands are recognized:<br \/>\nUSER   PASS   QUIT   CWD    PWD    PORT   PASV   TYPE<br \/>\nLIST   REST   CDUP   RETR   STOR   SIZE   DELE   RMD<br \/>\nMKD    RNFR   RNTO   ABOR   SYST   NOOP   APPE   NLST<br \/>\nMDTM   XPWD   XCUP   XMKD   XRMD   NOP    EPSV   EPRT<br \/>\nAUTH   ADAT   PBSZ   PROT   FEAT   MODE   OPTS   HELP<br \/>\nALLO   MLST   MLSD   SITE   P@SW   STRU   CLNT   MFMT<br \/>\nHASH<br \/>\n<\/code><\/p>\n<p>The other overload of <em>SendCommand <\/em>allows you to specify, <strong>if after negative response exception is thrown<\/strong>.<\/p>\n<p>The next sample will not throw exception if the server does not recognize the command.<br \/>\nYou can examine <em>IsPositive<\/em> property to check if the response was successful or not.<\/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    client.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    FtpResponse response = client.SendCommand(&quot;HELP&quot;, false);\r\n\r\n    Console.WriteLine(response.IsPositive);\r\n    Console.WriteLine(response.Message);\r\n    foreach (string line in response.Lines)\r\n        Console.WriteLine(line);\r\n\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\tclient.Connect(&quot;ftp.example.org&quot;)\r\n\tclient.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n\tDim response As FtpResponse = client.SendCommand(&quot;HELP&quot;, False)\r\n\r\n\tConsole.WriteLine(response.IsPositive)\r\n\tConsole.WriteLine(response.Message)\r\n\tFor Each line As String In response.Lines\r\n\t\tConsole.WriteLine(line)\r\n\tNext\r\n\r\n\r\n\tclient.Close()\r\nEnd Using\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>This article describes how to issue a custom command to FTP server using Ftp.dll &#8211; .NET FTP and FTPS library. \/\/ C# version using (Ftp client = new Ftp()) { client.Connect(&quot;ftp.example.org&quot;); client.Login(&quot;user&quot;, &quot;password&quot;); FtpResponse response = client.SendCommand(&quot;HELP&quot;); Console.WriteLine(response.Message); foreach (string line in response.Lines) Console.WriteLine(line); client.Close(); } &#8216; VB.NET version Using client As New Ftp() client.Connect(&quot;ftp.example.org&quot;) [&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,57],"class_list":["post-1527","post","type-post","status-publish","format-standard","hentry","category-ftp-dll","tag-c","tag-ftp","tag-ftp-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1527"}],"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=1527"}],"version-history":[{"count":5,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1527\/revisions"}],"predecessor-version":[{"id":4136,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1527\/revisions\/4136"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}