Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using ListDirectoryDetails
Message
From
17/04/2010 15:01:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
17/04/2010 14:55:56
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01460672
Message ID:
01460758
Views:
33
>>I thought the same way and looked it a little bit today. Though it sounded really weird to me here is what I have found. You use ListDirectoryDetails and parse the datetime part. But if it is in current year, directory listing has hour:minute instead of a year. If it is in another year then it lists the year. Here is a listing w/o parsin further:
>>
>>
>>void Main()
>>{
>>   Uri uri = new Uri("ftp://ftp.prolib.de/Public");
>>   FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(uri); 
>>	 
>>   req.Credentials = new NetworkCredential ("anonymous", "password");
>>   req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
>>   string details;
>>   using(FtpWebResponse resp  = (FtpWebResponse)req.GetResponse())
>>   using(Stream stream = resp.GetResponseStream())
>>   using(StreamReader reader = new StreamReader(stream))
>>	 {
>>	  details = reader.ReadToEnd();
>>	 }
>>	 Console.WriteLine (details);
>>}
>>
And here is the list I got:
>>
drw-rw-rw-   1 user     group           0 Apr 11 13:23 .
>>drw-rw-rw-   1 user     group           0 Apr 11 13:23 ..
>>-rw-rw-rw-   1 user     group     1823921 Apr 11 13:23 FoxHelp_Win26_GER.zip
>>drw-rw-rw-   1 user     group           0 Mar 30  2007 FoxPro
>>-rw-rw-rw-   1 user     group        4408 Oct 20 04:30 ReadMe_Runtime.txt
>>drw-rw-rw-   1 user     group           0 Dec  8  2008 VFP
>>-rw-rw-rw-   1 user     group     7685314 Oct 12  1999 VFP3SP1RT.EXE
>>-r--r--r--   1 user     group     1454080 Dec 14  1997 VFP5SP1RT.EXE
>>-r--r--r--   1 user     group     1454080 Dec 14  1997 VFP5SP1RT.W02
>>-r--r--r--   1 user     group       34177 Dec 14  1997 VFP5SP1RT.W03
>>-rw-rw-rw-   1 user     group     6177190 Oct 20 04:22 VFP6SP5RT.EXE
>>-rw-rw-rw-   1 user     group     6300577 Sep 21  2001 VFP7SP0RT.EXE
>>-rw-rw-rw-   1 user     group    10089422 Oct 20 02:48 VFP7SP1RT.exe
>>-rw-rw-rw-   1 user     group     9441214 Jun 27  2003 VFP8SP0RT.EXE
>>-rw-rw-rw-   1 user     group    11042282 Oct 20 02:49 VFP8SP1RT.exe
>>-rw-rw-rw-   1 user     group    12989444 Oct 20 02:50 VFP9SP0RT.exe
>>-rw-rw-rw-   1 user     group    12722668 Oct 20 02:51 VFP9SP1RT.exe
>>-rw-rw-rw-   1 user     group    12837733 Oct 20 04:24 VFP9SP2RT.exe
>>drw-rw-rw-   1 user     group           0 Mar 30  2007 Why_VFP
>>
Strangely you can see entries in future.
>>
>>Update: I take my word back. Checking their times using GetDateTimestamp reveals different date and times than those displayed in list ( now I have no idea what those date/time in listing stand for).
>
>Very interesting, at least with the year, it is always better than to have to query one by one to get that information.

Here is the more detailed version that I promised:
using System;
using System.Linq;
using System.Net;
using System.IO;

namespace CBSample
{
    class FtpSmaple
    {
        void Main()
        {
            string baseUri = "ftp://ftp.prolib.de/Public";
            Uri uri = new Uri(baseUri);
            FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(uri);
            req.Proxy = null;
            req.Credentials = new NetworkCredential("anonymous", "password");
            req.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

            string files;
            using (FtpWebResponse resp = (FtpWebResponse)req.GetResponse())
            using (Stream stream = resp.GetResponseStream())
            using (StreamReader reader = new StreamReader(stream))
            {
                files = reader.ReadToEnd();
            }

            foreach (var file in files.Replace("\r", "").Split('\n'))
            {
                string fName = file.Split(' ').Last();
                bool isDirectory = file.StartsWith("d", true, null);
                if (!fName.StartsWith(".") && fName != "")
                {
                    MyInfo info =
                           GetFileInfo(baseUri, fName);
                    Console.WriteLine("{0,-10}: {1,-30} | Modified: {2:yyyy/MM/dd HH:mm:ss}",
                          isDirectory ? "Directory" : "File",
                              info.FileName,
                              info.LastModified);
                }
            }
        }

        private MyInfo GetFileInfo(string baseuri, string fileName)
        {
            MyInfo result = new MyInfo();
            result.FileName = fileName;
            Uri uri = new Uri(String.Format("{0}/{1}", baseuri, fileName));
            FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(uri);

            req.Proxy = null;
            req.Credentials = new NetworkCredential("anonymous", "password");
            req.Method = WebRequestMethods.Ftp.GetDateTimestamp;
            using (FtpWebResponse resp = (FtpWebResponse)req.GetResponse())
            {
                result.LastModified = resp.LastModified;
            }
            return result;
        }
    }

    class MyInfo
    {
        public string FileName;
        public DateTime LastModified;
    }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform