This should work without a HTML file (if that isn't a requirement), have tested it and it produces a 100MB zip file in C:\temp
called newfile.zip
.
Just remember when you execute the command, do so in an elevated context.
cscript //nologo "myscript.vbs"
Code myscript.vbs
Option Explicit
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Call main()
Sub main()
Dim url: url = "https://ams-nl-ping.vultr.com/vultr.com.100MB.bin"
Dim path: path = "c:\temp\newfile.zip"
Dim resp: resp = downloadFromURL(url)
If Not IsEmpty(resp) Then
Call SaveStreamToFile(resp, path)
Else
Call WScript.Echo("Failed to download from " & url)
End If
End Sub
Function downloadFromURL(url)
Dim http: Set http = CreateObject("MSXML2.XMLHTTP.6.0")
Dim stream
Call http.Open("GET", url, False)
Call http.Send()
If http.Status = 200 Then
downloadFromURL = http.responseBody
Else
downloadFromURL = Empty
End If
End Function
Sub SaveStreamToFile(resp, path)
Dim stream: Set stream = CreateObject("ADODB.Stream")
With stream
Call .Open()
.Type = adTypeBinary
Call .Write(resp)
Call .SaveToFile(path, adSaveCreateOverWrite)
Call .Close()
End With
End Sub
There are lots of ways this could be improved, at the moment the variables url
and path
are hardcoded but could be passed in using the WScript.Arguments
collection, allowing you to pass the values as parameters of the script on the command line. Could also improve the error handling passing back the StatusText
from HTTP request, but will leave this to you.
This is simply a bare bones example, intended to be built on.