CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Ftp directory listing

    I'm attempting to get a detailed directory listing from an Ftp server.

    When I navigate to the directory in IE, I get

    Code:
    09/07/2009 07:48AM      Directory 090609
    09/08/2009 07:38AM      Directory 090610
    01/01/1980 12:00AM      Directory 930101
    08/10/2009 11:21PM      Directory 090513
    08/12/2009 07:44AM      Directory 090514
    08/13/2009 07:38AM      Directory 090515
    08/14/2009 07:47AM      Directory 090516
    08/15/2009 07:50AM      Directory 090517
    08/16/2009 07:55AM      Directory 090518
    08/17/2009 07:41AM      Directory 090519
    08/18/2009 07:42AM      Directory 090520
    08/19/2009 08:06AM      Directory 090521
    08/20/2009 07:47AM      Directory 090522
    08/21/2009 07:43AM      Directory 090523
    08/22/2009 07:58AM      Directory 090524
    However, when I retrieve it in code, it appears as:

    Code:
    dr--rw----   1 admin      data                0 Jan  1  1980 .
    dr--rw----   1 admin      data                0 Jan  1  1980 ..
    dr--rw----   1 admin      data                0 Sep  7 07:48 090609
    dr--rw----   1 admin      data                0 Sep  8 07:38 090610
    dr--rw----   1 admin      data                0 Jan  1  1980 930101
    dr--rw----   1 admin      data                0 Aug 10 23:21 090513
    dr--rw----   1 admin      data                0 Aug 12 07:44 090514
    dr--rw----   1 admin      data                0 Aug 13 07:38 090515
    dr--rw----   1 admin      data                0 Aug 14 07:47 090516
    dr--rw----   1 admin      data                0 Aug 15 07:50 090517
    dr--rw----   1 admin      data                0 Aug 16 07:55 090518
    dr--rw----   1 admin      data                0 Aug 17 07:41 090519
    dr--rw----   1 admin      data                0 Aug 18 07:42 090520
    dr--rw----   1 admin      data                0 Aug 19 08:06 090521
    dr--rw----   1 admin      data                0 Aug 20 07:47 090522
    dr--rw----   1 admin      data                0 Aug 21 07:43 090523
    dr--rw----   1 admin      data                0 Aug 22 07:58 090524
    The main issue is that the complete date isn't appearing.

    Here's the code I'm using.
    Code:
    FtpWebRequest ftpclientRequest = WebRequest.Create( args[ 0 ] ) asFtpWebRequest;
    
    ftpclientRequest.Credentials = newNetworkCredential( "un", "pw" );
    ftpclientRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
    ftpclientRequest.Proxy = null;
     
    using( FtpWebResponse response = ftpclientRequest.GetResponse( ) asFtpWebResponse )
    {
      StreamReader sr = newStreamReader( response.GetResponseStream( ), System.Text.Encoding.ASCII );
      string datastring = sr.ReadToEnd( );
    }


    Any idea how I could retrieve the data as it appears in IE (actually all I need is the complete date and the directory name entries).

    Thanks.
    Last edited by Arjay; September 23rd, 2009 at 11:55 PM.

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Ftp directory listing

    090513 - extract the 1st 2 digits which is the year - 2009
    and month / date you already have it...

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Ftp directory listing

    Quote Originally Posted by vcdebugger View Post
    090513 - extract the 1st 2 digits which is the year - 2009
    and month / date you already have it...
    No I don't. While the directory names appear to be related to a date, they aren't.

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Ftp directory listing

    That depends on directory listing format provided by FTP server. For current century, it's not giving 2-extra digits.

    See the attached file, which parses the directory listing from various format. You need to spend some time, to understand how it's working!

    Find IsUNIXStyleListing in the file, and see comments above it.
    Attached Files Attached Files
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Join Date
    Jul 2006
    Posts
    297

    Re: Ftp directory listing

    Code:
    09/07/2009 07:48AM      Directory 090609
    Code:
    dr--rw----   1 admin      data                0 Sep  7 07:48 090609
    Seems like you're missing the Year somehow all the other data is there.

    But what i find interesting is this

    Code:
    01/01/1980 12:00AM      Directory 930101
    Code:
    dr--rw----   1 admin      data                0 Jan  1  1980 930101
    This one has a year but no time...
    Last edited by monalin; September 24th, 2009 at 02:01 PM.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Ftp directory listing

    Thanks for looking into this, guys.

    My original post didn't include enough of the directory sample.

    The snippet below is what IE shows me when I navigate to the ftp folder.

    Code:
    09/21/2009 07:40AM      Directory 090623
    09/22/2009 07:44AM      Directory 090624
    09/23/2009 07:39AM      Directory 090625
    09/24/2009 07:37AM      Directory 090626
    09/25/2009 07:41AM      Directory 090627
    09/26/2008 07:58AM      Directory 090628
    09/27/2008 08:00AM      Directory 090629
    09/28/2008 07:40AM      Directory 090630
    09/29/2008 07:44AM      Directory 090701
    09/30/2008 07:40AM      Directory 090702
    10/01/2008 07:48AM      Directory 090703
    Notice the highlighted date in red and how how the date is from a year ago?

    The whole reason for my code is that I'm trying to detect an older date than present.

    I figured if I can read the directory listing like how Internet Explorer does, then I can parse the data and detect the older date.

    As mentioned before, the problem is that when I progammatically read the data, it comes back without the complete date

    Code:
     
    dr--rw----   1 admin      data                0 Aug 14 07:47 090516
    @Ajay. It is indeed Unix (TinyFtp), and thanks for your reply but the issue isn't parsing the data. The problem is that the data doesn't come back with what I need.

    Is there another approach that I can take that will allow me to retrieve the data like I see in Internet Explorer?

  7. #7
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Ftp directory listing

    ftp has two different types of directory listing commands, NLST and LIST. It could be that the api is using list and explorer is using nlst (which I think returns more info).

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Ftp directory listing

    Thanks MadHatter. Here's what the Ftp commands are defined as:

    Code:
    publicconststring AppendFile = "APPE";
    publicconststring DeleteFile = "DELE";
    publicconststring DownloadFile = "RETR";
    publicconststring GetDateTimestamp = "MDTM";
    publicconststring GetFileSize = "SIZE";
    publicconststring ListDirectory = "NLST";
    publicconststring ListDirectoryDetails = "LIST";
    publicconststring MakeDirectory = "MKD";
    publicconststring PrintWorkingDirectory = "PWD";
    publicconststring RemoveDirectory = "RMD";
    publicconststring Rename = "RENAME";
    publicconststring UploadFile = "STOR";
    publicconststring UploadFileWithUniqueName = "STOU";


    I've tried all the appropriate ones.

    At any rate, I ended up solving the problem another way.

    Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured