The example VBS script below shows how to download and save a file from a remote webserver using Microsoft VBS scripting. It can handle http/https and user authentication, using the MSXML2.XMLHTTP.3.0 method. The method could also handle client cert authentication, if necessary.

Due to the widespread use of self-signed, untrusted certificates for enabling https, it might be necessary to explicitly disable the verification. an example line has been included below, and more information can be found here (Microsoft Dev Center - Desktop, XML DOM Methods, set- and getOption).

' http-download.vbs 1.0 @2011 by Frank4dd
' This script demonstrates a file download from a webserver using http(s).
' It can easily be extended for using basic web authentication.
' This program comes with ABSOLUTELY NO WARRANTY. You may redistribute
' copies of it under the terms of the GNU General Public License.

' Global Constants and Variables
Const scriptVer  = "1.0"
Const DownloadDest = ""
Const LocalFile = "C:\tmp.gif"
'Const webUser = "username"
'Const webPass = "password"
Const DownloadType = "binary"
dim strURL

function getit()
  dim xmlhttp

  set xmlhttp=createobject("MSXML2.XMLHTTP.3.0")
  'xmlhttp.SetOption(2, 13056) 'If url https -> Ignore all SSL errors
  strURL = DownloadDest
  msgbox "Download-URL: " & strURL

  'For basic auth, use the line below together with user+pass variables above
  'xmlhttp.Open "GET", strURL, false, webUser, webPass
  xmlhttp.Open "GET", strURL, false

  Wscript.Echo "Download-Status: " & xmlhttp.Status & " " & xmlhttp.statusText
  If xmlhttp.Status = 200 Then
    Dim objStream
    set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1 'adTypeBinary
    objStream.Write xmlhttp.responseBody
    objStream.SaveToFile LocalFile
    set objStream = Nothing
  End If

  set xmlhttp=Nothing
End function 

' End Function Defs, Start Main
' Get cmdline params and initialize variables
If Wscript.Arguments.Named.Exists("h") Then
  Wscript.Echo "Usage: http-download.vbs"
  Wscript.Echo "version " & scriptVer
End If

Wscript.Echo "Download Complete. See " & LocalFile & " for success."
' End Main

Example Run Screenshots

example screenshot 1 for http-download.vbs

example screenshot 2 for http-download.vbs

example screenshot 3 for http-download.vbs

example screenshot 4 for http-download.vbs

MSXML2.XMLHTTP.3.0 Options Reference

A limited set of options helps to control the handling of HTTP(S) requests:

Usage: Identify last URL, i.e. after redirects Value: String that contains the final, last used URL
Example: lastUrl = xmlhttp.getOption(-1)

Usage: Overide standard UTF-8 codepage Value: Integer of the new codepage

Usage: Enable escape for % character Value: Boolean true/false

Usage: Disable SSL trust verification. Values:

Usage: Set client certificate name (local certstore) Value: Name string


See Also: