{"id":1550,"date":"2010-11-07T15:19:12","date_gmt":"2010-11-07T13:19:12","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=1550"},"modified":"2012-06-03T15:20:44","modified_gmt":"2012-06-03T13:20:44","slug":"get-file-folder-info-using-ftp","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/get-file-folder-info-using-ftp","title":{"rendered":"Get file or folder info using FTP"},"content":{"rendered":"<p>Server responses to FTP protocol&#8217;s LIST command are not well standardized. Ftp.dll <a href=\"\/ftp\">FTP .NET component<\/a> was programmed to handle almost any format of such response. This includes UNIX, Linux and Windows systems. Additionally if a server supports better standardized MLSD command, it is used instead of LIST.<\/p>\n<p>To list all files and folders in current folder just use <em>GetList<\/em> method of <em>Ftp<\/em> class.<br \/>\nYou&#8217;ll receive <em>FtpItem <\/em> collection you can easy iterate over. You can access each item&#8217;s information like: name, size, modification date by using <em>FtpItem<\/em>&#8216;s properties.<\/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;);    \/\/ or ConnectSSL for SSL\r\n    client.Login(&quot;user&quot;, &quot;password&quot;);\r\n\r\n    List&lt;FtpItem&gt; items = client.GetList();\r\n\r\n    foreach (FtpItem item in items)\r\n    {\r\n        Console.WriteLine(&quot;Name:        {0}&quot;, item.Name);\r\n        Console.WriteLine(&quot;Size:        {0}&quot;, item.Size);\r\n        Console.WriteLine(&quot;Modify date: {0}&quot;, item.ModifyDate);\r\n\r\n        Console.WriteLine(&quot;Is folder:   {0}&quot;, item.IsFolder);\r\n        Console.WriteLine(&quot;Is file:     {0}&quot;, item.IsFile);\r\n        Console.WriteLine(&quot;Is symlink:  {0}&quot;, item.IsSymlink);\r\n\r\n        Console.WriteLine();\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;)    ' or ConnectSSL for SSL\r\n\tclient.Login(&quot;user&quot;, &quot;password&quot;)\r\n\r\n\tDim items As List(Of FtpItem) = client.GetList()\r\n\r\n\tFor Each item As FtpItem In items\r\n\t\tConsole.WriteLine(&quot;Name:        {0}&quot;, item.Name)\r\n\t\tConsole.WriteLine(&quot;Size:        {0}&quot;, item.Size)\r\n\t\tConsole.WriteLine(&quot;Modify date: {0}&quot;, item.ModifyDate)\r\n\r\n\t\tConsole.WriteLine(&quot;Is folder:   {0}&quot;, item.IsFolder)\r\n\t\tConsole.WriteLine(&quot;Is file:     {0}&quot;, item.IsFile)\r\n\t\tConsole.WriteLine(&quot;Is symlink:  {0}&quot;, item.IsSymlink)\r\n\r\n\t\tConsole.WriteLine()\r\n\tNext\r\n\r\n\tclient.Close()\r\nEnd Using\r\n<\/pre>\n<h2>Getting basic file information using FTP<\/h2>\n<p>Follow code illustrates how to get basic information about specific file, such as size and last modification date, using FTP protocol:<\/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    long size = client.GetFileSize(&quot;reports\/report_2010.txt&quot;);\r\n    DateTime date = client.GetFileModificationTime(&quot;reports\/report_2010.txt&quot;);\r\n\r\n    Console.WriteLine(&quot;Size:        {0}&quot;, size);\r\n    Console.WriteLine(&quot;Modify date: {0}&quot;, date);\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 size As Long = client.GetFileSize(&quot;reports\/report_2010.txt&quot;)\r\n\tDim &#x5B;date] As DateTime = client.GetFileModificationTime(&quot;reports\/report_2010.txt&quot;)\r\n\r\n\tConsole.WriteLine(&quot;Size:        {0}&quot;, size)\r\n\tConsole.WriteLine(&quot;Modify date: {0}&quot;, &#x5B;date])\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>Server responses to FTP protocol&#8217;s LIST command are not well standardized. Ftp.dll FTP .NET component was programmed to handle almost any format of such response. This includes UNIX, Linux and Windows systems. Additionally if a server supports better standardized MLSD command, it is used instead of LIST. To list all files and folders in current [&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-1550","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\/1550"}],"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=1550"}],"version-history":[{"count":10,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1550\/revisions"}],"predecessor-version":[{"id":3066,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/1550\/revisions\/3066"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=1550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=1550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=1550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}