Skip to content

Instantly share code, notes, and snippets.

@udawtr
Last active March 23, 2023 04:47
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save udawtr/2053179 to your computer and use it in GitHub Desktop.
Save udawtr/2053179 to your computer and use it in GitHub Desktop.
wget.vbs - similar to wget but written in vbscript
'wget.vbs - similar to wget but written in vbscript
'based on a script by Chrissy LeMaire
' Usage
if WScript.Arguments.Count < 1 then
MsgBox "Usage: wget.vbs <url> (file)"
WScript.Quit
end if
' Arguments
URL = WScript.Arguments(0)
if WScript.Arguments.Count > 1 then
saveTo = WScript.Arguments(1)
else
parts = split(url,"/")
saveTo = parts(ubound(parts))
end if
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "GET", URL, false
objXMLHTTP.send()
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(saveTo) Then objFSO.DeleteFile saveTo
Set objFSO = Nothing
objADOStream.SaveToFile saveTo
objADOStream.Close
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
' Done
WScript.Quit
@pravyroxor
Copy link

Some zip files downloaded using this script ending with error:
Line: 31
Char: 1
Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Code: 800A0BB9
Source: ADODB.Stream

@Robkof2002
Copy link

Resolvendo erro : NET::ERR_CERT_COMMON_NAME_INVALID

'wget.vbs - similar to wget but written in vbscript
'based on a script by Chrissy LeMaire

' Usage
if WScript.Arguments.Count < 1 then
MsgBox "Usage: wget.vbs (file)"
WScript.Quit
end if

' Arguments
URL = WScript.Arguments(0)
if WScript.Arguments.Count > 1 then
saveTo = WScript.Arguments(1)
else
parts = split(url,"/")
saveTo = parts(ubound(parts))
end if

' Fetch the file
Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")

objXMLHTTP.open "GET", URL, false
objXMLHTTP.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
Call objXMLHTTP.SetRequestHeader("Content-Type", "text/xml")
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary

objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start

Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(saveTo) Then objFSO.DeleteFile saveTo
Set objFSO = Nothing

objADOStream.SaveToFile saveTo
objADOStream.Close
Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing

' Done
WScript.Quit

@bofhbug
Copy link

bofhbug commented May 15, 2019

Please note: This only works with http: or https with the outdated TLS 1.0
TLS 1.2 is NOT a default secure protocol in WinHTTP in Windows:
https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-a-default-secure-protocols-in
https://gist.github.com/BitNetwork/b6f7ef23fac1044e5dfb1187fd1936af#gistcomment-2609387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment