Home All Groups Group Topic Archive Search About

VB.NET 2005 WebClient file download via HTTPS

Author
25 Sep 2006 3:50 PM
Chad T
I am very new to VB.Net (most of my experience is with vbscript)
My goal is to create a executable to download files from a HTTPS server.
I have to pass the credentials to the https server.

The code below works fine on our IIS server configured for https but when I
connect to a remote server running "IBM_HTTP_Server/2.0.47.1-PK29827
Apache/2.0.47 (Win32) Server" The error I get is Unauthorized...

My Error: The remote server returned an error: (401) Unauthorized.

How can I fix this so it works on any https server... or is there a better
way to do this?


'************Code starts here
Imports System.IO
Imports System.Net
Imports System.Text

Module Module1
    Sub Main()
        Dim fullfiledownload As String
        Dim filefullpath As String

        Dim fileurl As String = "https://someserver/"
        Dim filedownload As String = "fcs_hail_data_06.txt"
        Dim newfilename As String = "Igotit.TXT"
        Dim filepath As String = "C:\"
        Dim userid As String = "userid"
        Dim userpassword As String = "password"

        fullfiledownload = fileurl & filedownload
        filefullpath = filepath & newfilename

                    Dim wc As New WebClient
                    Dim myCredentials As New NetworkCredential(userid,
userpassword)
                    wc.Credentials = myCredentials
                    wc.DownloadFile(fullfiledownload, filefullpath)
    End Sub
End Module

Author
25 Sep 2006 4:33 PM
Patrice
Does it work "by hand" with these credentials ? It would likely allows to
see if the credentials and/or the file permission are not correct or if this
is a problem with the code...



--

"Chad T" <Ch***@discussions.microsoft.com> a écrit dans le message de news:
8D01600A-5214-4704-AD4A-3B5ACDDC1***@microsoft.com...
Show quoteHide quote
>I am very new to VB.Net (most of my experience is with vbscript)
> My goal is to create a executable to download files from a HTTPS server.
> I have to pass the credentials to the https server.
>
> The code below works fine on our IIS server configured for https but when
> I
> connect to a remote server running "IBM_HTTP_Server/2.0.47.1-PK29827
> Apache/2.0.47 (Win32) Server" The error I get is Unauthorized...
>
> My Error: The remote server returned an error: (401) Unauthorized.
>
> How can I fix this so it works on any https server... or is there a better
> way to do this?
>
>
> '************Code starts here
> Imports System.IO
> Imports System.Net
> Imports System.Text
>
> Module Module1
>    Sub Main()
>        Dim fullfiledownload As String
>        Dim filefullpath As String
>
>        Dim fileurl As String = "https://someserver/"
>        Dim filedownload As String = "fcs_hail_data_06.txt"
>        Dim newfilename As String = "Igotit.TXT"
>        Dim filepath As String = "C:\"
>        Dim userid As String = "userid"
>        Dim userpassword As String = "password"
>
>        fullfiledownload = fileurl & filedownload
>        filefullpath = filepath & newfilename
>
>                    Dim wc As New WebClient
>                    Dim myCredentials As New NetworkCredential(userid,
> userpassword)
>                    wc.Credentials = myCredentials
>                    wc.DownloadFile(fullfiledownload, filefullpath)
>    End Sub
> End Module