Click to See Complete Forum and Search --> : Ftp directory listing


Arjay
September 23rd, 2009, 11:50 PM
I'm attempting to get a detailed directory listing from an Ftp server.

When I navigate to the directory in IE, I get


09/07/2009 07:48AM Directory 090609 (ftp://10.5.6.107/A/d/090609/)
09/08/2009 07:38AM Directory 090610 (ftp://10.5.6.107/A/d/090610/)
01/01/1980 12:00AM Directory 930101 (ftp://10.5.6.107/A/d/930101/)
08/10/2009 11:21PM Directory 090513 (ftp://10.5.6.107/A/d/090513/)
08/12/2009 07:44AM Directory 090514 (ftp://10.5.6.107/A/d/090514/)
08/13/2009 07:38AM Directory 090515 (ftp://10.5.6.107/A/d/090515/)
08/14/2009 07:47AM Directory 090516 (ftp://10.5.6.107/A/d/090516/)
08/15/2009 07:50AM Directory 090517 (ftp://10.5.6.107/A/d/090517/)
08/16/2009 07:55AM Directory 090518 (ftp://10.5.6.107/A/d/090518/)
08/17/2009 07:41AM Directory 090519 (ftp://10.5.6.107/A/d/090519/)
08/18/2009 07:42AM Directory 090520 (ftp://10.5.6.107/A/d/090520/)
08/19/2009 08:06AM Directory 090521 (ftp://10.5.6.107/A/d/090521/)
08/20/2009 07:47AM Directory 090522 (ftp://10.5.6.107/A/d/090522/)
08/21/2009 07:43AM Directory 090523 (ftp://10.5.6.107/A/d/090523/)
08/22/2009 07:58AM Directory 090524 (ftp://10.5.6.107/A/d/090524/)


However, when I retrieve it in code, it appears as:


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.

FtpWebRequest ftpclientRequest = WebRequest.Create( args[ 0 ] ) as FtpWebRequest;

ftpclientRequest.Credentials = new NetworkCredential( "un", "pw" );
ftpclientRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
ftpclientRequest.Proxy = null;

using( FtpWebResponse response = ftpclientRequest.GetResponse( ) as FtpWebResponse )
{
StreamReader sr = new StreamReader( 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.

vcdebugger
September 24th, 2009, 01:03 AM
090513 - extract the 1st 2 digits which is the year - 2009
and month / date you already have it...

Arjay
September 24th, 2009, 11:33 AM
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.

Ajay Vijay
September 24th, 2009, 12:31 PM
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.

monalin
September 24th, 2009, 01:57 PM
09/07/2009 07:48AM Directory 090609

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

01/01/1980 12:00AM Directory 930101
dr--rw---- 1 admin data 0 Jan 1 1980 930101

This one has a year but no time...

Arjay
September 24th, 2009, 07:38 PM
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.


09/21/2009 07:40AM Directory 090623 (ftp://10.5.6.107/A/d/090623/)
09/22/2009 07:44AM Directory 090624 (ftp://10.5.6.107/A/d/090624/)
09/23/2009 07:39AM Directory 090625 (ftp://10.5.6.107/A/d/090625/)
09/24/2009 07:37AM Directory 090626 (ftp://10.5.6.107/A/d/090626/)
09/25/2009 07:41AM Directory 090627 (ftp://10.5.6.107/A/d/090627/)
09/26/2008 07:58AM Directory 090628 (ftp://10.5.6.107/A/d/090628/)
09/27/2008 08:00AM Directory 090629 (ftp://10.5.6.107/A/d/090629/)
09/28/2008 07:40AM Directory 090630 (ftp://10.5.6.107/A/d/090630/)
09/29/2008 07:44AM Directory 090701 (ftp://10.5.6.107/A/d/090701/)
09/30/2008 07:40AM Directory 090702 (ftp://10.5.6.107/A/d/090702/)
10/01/2008 07:48AM Directory 090703 (ftp://10.5.6.107/A/d/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


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?

MadHatter
September 24th, 2009, 07:54 PM
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).

Arjay
September 24th, 2009, 10:13 PM
Thanks MadHatter. Here's what the Ftp commands are defined as:


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


I've tried all the appropriate ones.

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

Thanks everyone.