Hi Everyone,
Using vb 2005 how would I download a file from a password protected web directory?
Thanks in advance,
Dave
Printable View
Hi Everyone,
Using vb 2005 how would I download a file from a password protected web directory?
Thanks in advance,
Dave
There are a few ways to do it. This is probably the most simple form.
Code:Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("username", "password")
WC.DownloadFile("http://www.somesite.com/somedir/somefile.zip", "C:\somefile.zip")
End Using
Thanks for that :)
One more thing. Is there a way to get a list of all the files in the directory?
Thanks again,
Dave
If the webserver supports listing directory contents, otherwise you would need to use FTP classes/commands to get a directory listing.
It does support it directory listing. I'm just not sure how to go about doing it.
For HTTP directory listing, you would need to manually parse the links out of the page, since there is so real standard for directory listing structures over HTTP.
If you can do it via FTP, it will be a more solid approach.
Unfortunately FTP isn't an option.
Do you have control over the web server in question or no?
One option would be to have a server side scripted page (php, asp, asp.net, etc..) that could output a directory listing.
This way you know the exact format the given page will output, and makes it very easy to parse the data, since you know the format.
Otherwise, using the standard directory listing, you would need to use either standard string parsing, or regular expressions to extract the individual links out from the web servers directory listing.
I do over the one I'm working with right now but wont with some others that I am adding. Reading and parsing the html is likely my best option.