473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
<DIRin 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 <DIRtag) 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

Mar 20 '07 #1
7 4923
On Mar 20, 9:33 am, Bill <B...@discussions.microsoft.comwrote:
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
<DIRin 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 <DIRtag) 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?

Mar 20 '07 #2
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
"Alexey Smirnov" wrote:
On Mar 20, 9:33 am, Bill <B...@discussions.microsoft.comwrote:
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
<DIRin 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 <DIRtag) 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?

Mar 20 '07 #3
On Mar 20, 2:18 pm, Bill <B...@discussions.microsoft.comwrote:
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...

Mar 20 '07 #4
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
"Alexey Smirnov" wrote:
On Mar 20, 2:18 pm, Bill <B...@discussions.microsoft.comwrote:
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...

Mar 20 '07 #5
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)

Bill wrote:
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
<DIRin 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 <DIRtag) 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
Mar 20 '07 #6
On Mar 20, 4:26 pm, bruce barker <nos...@nospam.comwrote:
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)

Bill wrote:
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
<DIRin 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 <DIRtag) 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- Hide quoted text -

- Show quoted text -
agree with Bruce

Take a look this code
http://www.codeproject.com/dotnet/do...select=1479202

and check the comments as well (there is a regex you may use to parse
the response)

Hope it helps

Mar 20 '07 #7
Thanks Bruce / Alexey

"bruce barker" wrote:
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)

Bill wrote:
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
<DIRin 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 <DIRtag) 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
Mar 21 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jean-Paul Lauque | last post by:
Hello, I'm beginning in the ASP world... I would like to sort (descending) list of files in directory. Parameter is directory url. How I can to do that with ASP not ASP.NET.
8
by: Opa | last post by:
Hi, Does anyone know how to get a list of files for a given directory from a given url. I have the following, but get an error indicating that URI formats are not supported. ...
5
by: jpasqua | last post by:
Is there an XP/SP out there that will return a list of files residing in a specified directory? I'm looking for something simlar to Execute master..xp_subdirs N'C:\' But instead of it...
3
by: greg chu | last post by:
If I type dir /s in the command line prompt I can list all system files ex. get into the IE temporary files C:\Documents and Settings\XXXXXX\Local Settings\Temporary Internet Files XXXXXX is...
2
by: qwweeeit | last post by:
Hi all, in a previous post I asked help for colorizing expanded tab. I wanted to list text files showing in colors LFs and the expanded tabs. I hoped to use only bash but, being impossible, I...
3
by: cmacn024 | last post by:
Hi folks, I've got a question for yas. I'm trying to write code that will open up a gzipped tar file using gnutar, and copy the list of files(including their directories) to a list variable in...
4
by: maglev_now | last post by:
I'm using .net 1.1 trying to get a list of files in folder on the server. The user would select the file they want to download from a DropDownList. Can someone tell me how this should be done? I...
4
by: | last post by:
I need to get a list of files in a directory, say c:\temp, and display it in a drop down list. How would I do that?
8
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to get a list of SQL Server Instances thru a VB.NET application. I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe from...
9
by: Bruno GUERPILLON | last post by:
Hi, I'd like, in a WIN32 environment, list all open files. Anyone got a clue how to do this ? Regards, Bruno.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.