How to get a list of only the files on an ftp server

G

Guest

I want to get a list of the files in an FTP folder. I have seen the example
of MSDN using the FtpWebRequest, and it's fairly trivial to execute an NLIST
command, but the trouble is that this includes directories too. I can
specify a pattern like *.* in the uri to exclude directories, but this then
does not return files without extensions and there may be some of those.

If I use LIST instead, I can tell the directories as they get tagged with
<DIR> in the results. i.e.

02-15-07 12:21PM 488 Fred.xml
02-15-07 12:21PM 488 Gary.xml
02-15-07 12:21PM 488 James
03-16-07 10:19AM <DIR> Kathy
03-16-07 11:19AM <DIR> Louise


But I'm not sure that I can rely on the filename always starting at the same
offset from the start of the line which makes parsing the results tricky.
From a google on the web, it looks like there's no defined standard for the
response to a LIST command so I don't want to rely on the layout of this.

I could use both calls and read the directory names from the results of LIST
(whatever followed a <DIR> tag) and then remove these names from the results
of a call to NLIST, but I'm wondering if there's a simpler way.

Cheers,

Bill
 
G

Guest

I want to get a list of the files in an FTP folder. I have seen the example
of MSDN using the FtpWebRequest, and it's fairly trivial to execute an NLIST
command, but the trouble is that this includes directories too. I can
specify a pattern like *.* in the uri to exclude directories, but this then
does not return files without extensions and there may be some of those.

If I use LIST instead, I can tell the directories as they get tagged with
<DIR> in the results. i.e.

02-15-07 12:21PM 488 Fred.xml
02-15-07 12:21PM 488 Gary.xml
02-15-07 12:21PM 488 James
03-16-07 10:19AM <DIR> Kathy
03-16-07 11:19AM <DIR> Louise

But I'm not sure that I can rely on the filename always starting at the same
offset from the start of the line which makes parsing the results tricky.
From a google on the web, it looks like there's no defined standard for the
response to a LIST command so I don't want to rely on the layout of this.

I could use both calls and read the directory names from the results of LIST
(whatever followed a <DIR> tag) and then remove these names from the results
of a call to NLIST, but I'm wondering if there's a simpler way.

Cheers,

Bill

Where the folder is located, on your box, or it is a remote public FTP
service?
 
G

Guest

At the moment, it's on a server in our DMZ where customers can upload files,
but it may well be on a external third party server in the future.

Cheers,
Bill
 
G

Guest

At the moment, it's on a server in our DMZ where customers can upload files,

If the folder is on the same server you can access it without using
FTP. Giving the necessary permissions to ASPNET you can work with that
folder as usual using Directory or the DirectoryInfo class...
 
G

Guest

Unfortunately I don't have access to the location as a unc path. My
applicaiton already works out whether it can do this by checking the scheme
on the Uri and if it can use unc or local paths names, it does use the
Directory class. In this case, however, I only have ftp access to the
location so I can't access it with Directory.GetFiles()

Cheers,
Bill
 
B

bruce barker

ftp has not defined any common switches to the ls command. i'd just
parse the response to filer out the <dir>.

-- bruce (sqlwork.com)
 
G

Guest

Thanks Bruce / Alexey

bruce barker said:
ftp has not defined any common switches to the ls command. i'd just
parse the response to filer out the <dir>.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top