Results 1 to 9 of 9

Thread: download a file?

  1. #1

    Thread Starter
    Banned
    Join Date
    Jul 2005
    Posts
    63

    download a file?

    Hi Everyone,

    Using vb 2005 how would I download a file from a password protected web directory?

    Thanks in advance,
    Dave

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: download a file?

    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

  3. #3

    Thread Starter
    Banned
    Join Date
    Jul 2005
    Posts
    63

    Re: download a file?

    Thanks for that

    One more thing. Is there a way to get a list of all the files in the directory?

    Thanks again,
    Dave

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: download a file?

    If the webserver supports listing directory contents, otherwise you would need to use FTP classes/commands to get a directory listing.

  5. #5

    Thread Starter
    Banned
    Join Date
    Jul 2005
    Posts
    63

    Re: download a file?

    It does support it directory listing. I'm just not sure how to go about doing it.

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: download a file?

    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.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jul 2005
    Posts
    63

    Re: download a file?

    Unfortunately FTP isn't an option.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: download a file?

    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.

  9. #9

    Thread Starter
    Banned
    Join Date
    Jul 2005
    Posts
    63

    Re: download a file?

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width