Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2059
  • Last Modified:

Download files from HTTPS Site that requires Login

I'm writing an App in VB6 that opens up an IE browser using the InternetExplorer object, then navigates to a https site, fills in the username and password fields and clicks the button to log in.
From there it navigates to a page within the site which contains a list of files (.PDF, .ZIP and .DOC files). I need an automated way to download this list of files, but I'm yet to find a way to do this. This also has to be done through an Authenticated Proxy.

I tried URLDownloadToFile, but it didn't work because I couldn't work out how to use it with authentication information (either for the website OR the Proxy). Can anyone clue me in here?

I'm trying to use the Internet Transfer Control, but I can't get that to work either.
Here's the code I'm using:

    Dim FileURL As String
    Dim i As Integer
    Dim b() As Byte
    Dim h As Integer

    Form1.Inet1.protocol = icHTTPS
    Form1.Inet1.UserName = Website_Username
    Form1.Inet1.Password = Website_Password
    Form1.Inet1.Proxy = Proxy_IP_Address
    Form1.Inet1.AccessType = icNamedProxy
    FileURL = "https://...filename.zip"
    b = Form1.Inet1.OpenURL(FileURL, icByteArray)
    h = FreeFile
    Open "D:\xxxx.zip" For Binary As #h
    Put #h, , b
    Close #h
    Debug.Print Form1.Inet1.ResponseCode & " Error Info : " & Form1.Inet1.ResponseInfo

If I don't set the Proxy and AccessType properties, it downloads a html file that tells me I failed to authenticate with the proxy server (the same one I see if I put in my username or password incorrectly in my web browser when accessing the interent normally). If I do set these properties, i get the debug message: "12029 Error Info : Cannot connect". Does anyone know how to set proxy username and password values with this control? I also should be connecting to the proxy on port 8080 - anyone know how this can be done?

Or, alternately, is there another way to download files in this situation? Is it possible to use the InternetExplorer Object to do it somehow?

Thanks for any help you can offer,
  • 2
1 Solution
Try this...

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
   Dim lngRetVal As Long
   lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
   If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
   DownloadFile "https://username:password@www.xxxxxxxxxxxx.com/MyDownload.pdf:8080", "c:\myDownload.pdf"
   MsgBox "Download completed...", vbInformation, "Download status"
End Sub
pinkoAuthor Commented:
Sorry, didn't work... It doesn't download a file at all.
After execution, lngRetVal returns a value of -2147024891

I tried using both my proxy username/password and website username/password for the values of 'username:password', but neither worked.
pinkoAuthor Commented:
I did find a 3rd party VB component that allows you to pass the cookie from the internet explorer object to the download component! Which seems to solve my problem!

The component is: IP*Works! SSL Visual Basic Edition from /n software and you can find more info on this here:

As i found my own answer, i'm going to ask to have this question moved to a PAQ and my points refunded. If anyone has any objection to this, please let me know.
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now