views:

2488

answers:

2

How do I download all files in a directory and all subdirectories on an HTTP server?

Thanks!

+4  A: 

By using a command-line tool like wget rather than reinventing the wheel.

Andy Lester
Unless one actually needs to do this programmatically.
jro
Not sure why using an external tool doesn't count as "programatically."
Andy Lester
cause "Jro" didn't give any code how to do it maybe? you just gave a command line tool....
Tony Lambert
+2  A: 

If directory browsing is enabled on the server then you can crawl the directory listings, i.e. Use HttpWebRequest to get the listing page, parse the response to find the file links, download each file (also with HttpWebRequest), navigate to each subfolder, rinse and repeat.

If directory browsing isn't enabled then you can't really download ALL files in ALL subdirectories because you can't know they exist.

However, you could still use HttpWebRequest to crawl the exposed web pages and download any linked files that are of interest.

stucampbell
What method should I use? HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create( url ); httpWebRequest.Method = "???";
@Greg, yes.@stucampbell, Is there a way to get a list of files? or I do have to crawl in the HTML stuff??
Shimmy