Download files from a website

r3plica

Well-known member
Joined
Mar 4, 2010
Messages
86
Programming Experience
3-5
I have this website that stores my template files for Word, Excel, etc and I need to be able to download them through my .Net Application.
I can easily download a file if I know the name, but I want it to parse all the files in the given web directory and download them, without me having to specify the file names.....
The code I have to download a single file (when I know the filename) is:

VB.NET:
    Private Shared Sub DownloadFile(ByVal uri As String, ByVal DestinationFile As String, Optional ByVal username As String = Nothing, Optional ByVal pwd As String = Nothing)
        Dim wc As New System.Net.WebClient
        If Not username Is Nothing AndAlso Not pwd Is Nothing Then
            wc.Credentials = New System.Net.NetworkCredential(username, pwd)
        End If

        wc.DownloadFile(uri, DestinationFile)
    End Sub

So now I basically need for find a way to loop the files on the website, and then download them.
Could someone help me out with this, I have searched everywhere....
 
HTTP protocol doesn't have any commands for listing files, but if server allows directory browsing then requesting a directory path will return the file listing, most servers disables this though.
If you have access to FTP for that folder it is also possible, since list commands are part of the protocol.
Otherwise if you have an ASP.Net application there you could include functionality to return a file listing.
 
Cheers John,
I thought that might be the case, thanks for your response :)
 
Back
Top