Download files from HTTPS Site that requires Login

Posted on 2003-03-27
Medium Priority
Last Modified: 2007-12-19
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,
Question by:pinko
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Expert Comment

ID: 8223310
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

Author Comment

ID: 8235433
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.

Author Comment

ID: 8310809
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.

Accepted Solution

Mindphaser earned 1000 total points
ID: 8347615
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question