Get list of files from web server directory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From my WindowsForms application I am trying to get a list of files from a
web server directory and download them onto my PC. I will not know the
filenames prior to going to the web server directory. Thus, I need to be able
to read the contents of the web server directory to get the filenames or just
download all the files directly.

Does anyone have some sample code which can do the above. I've tried using
WebClient.DownloadFile but it needs to know the filenames in advance which I
do not have.

Many thanks in advance.
 
Hi Rob,
If you have control over the webserver you can add a web service that
returns the list of files. If you cannot add a webservice to the server
and the server had directory browsing turned on then you can parse out the
returned html page and grab the file names. If you cannot use a webservice
and directory browsing is not turned on, then I don't know of a way to do
this. Other than that, if the server also allowed FTP connections this
would be easy using the FTP functionality built into .net.

If you do have access to the server let us know and I can expand on the
webservice and directory browsing options. Otherwise maybe someone else
out there might have some ideas.

HTH,
Nathan
 
I do have access to the server within some limitations. The directory
browsing option seems like the best bet at this point (they have reservations
about web servoices). If you could expand on that idea, would be great.
Thanks.

What is the namspace for the FTP functionality (System.Net...)?
 
All you have to do is turn directory browsing on in IIS for the vdirs you
want to get the list of files. Next just use IE to browse to that vdir.
ex. http://mysite/myvdir. IIS will spit out html page that contains links
to the files and directories (do this just so you can see what the format
of the page is). Simply use a webrequest to request this page and parse
("screen scrape") the links. This isn't as elegant as a webservice but
should work ok.

As for FTP support I don't think there is a wrapper in the base class
library but the FTP protocal is prety straight forward and you can use the
functionality in the System.Net namespace to implement your own ftp client.
Otherwise, there are ton of FTP components available by third parties
(free and otherwise).

Nathan
 
Back
Top