tags:

views:

88

answers:

4

Hello :)

I'm a little lost for words atm so I'll try to use made-up code to explain what I'm trying to do...

foreach file in http://host.com/directory1/directory2/
   download file

Does that make any sense? I'm trying to download all files from a specified directory from a web server where my website's hosted. I know how to download a single file at a time but there are thousands of files and i just want every file inside one folder. Hmm... Can anybody offer any advice please?

thanks :-)

+2  A: 

The http protocol does not (as far as I know) have any commands for file listings (that's why there is FTP - File Transfer Protocol). Can you access the directory using an FTP connection instead? If so, you can list the directory contents and download the files using FTP requests instead.

Fredrik Mörk
A: 

If you only have http access and you don't have control over the server then...

Your only choice is to use some RegEx to scrape the list of file details from the HTML sent in the response to http://host.com/directory1/directory2/ and that of course depends on directory listing being enabled on the server.

You then will need to loop the set of acquired filenames and download individually.

AnthonyWJones
A: 

My host does not allow FTP or scripting or anything. But I DO know exactly how many files are in each folder.

So, what I've just decided to do is put it in a for loop, and once there are the right amount of files that have been downloaded onto my hard drive, then I'll get myself out of the loop. Thank you all for your answers.

It may not be the ideal solution but it seems to be the only solution.

baeltazor
A: 

What I usually do for this case is allow the user to select all the files they would like to download. The files are then zipped up into one archive using SharpZipLib and I return that file.

You may want to constrain the maximum file size in this case, depending upon how big or compressible your data is.

RedFilter