Create a gist now

Instantly share code, notes, and snippets.

@udawtr /wget.vbs
Last active Nov 13, 2017

What would you like to do?
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)"
end if
' Arguments
URL = WScript.Arguments(0)
if WScript.Arguments.Count > 1 then
saveTo = WScript.Arguments(1)
parts = split(url,"/")
saveTo = parts(ubound(parts))
end if
' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") "GET", URL, false
If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
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
Set objADOStream = Nothing
End if
Set objXMLHTTP = Nothing
' Done

MSXML2.ServerXMLHTTP can be used in place of MSXML2.XMLHTTP if you encounter "Access is denied" errors.


udawtr commented Nov 28, 2013

Thanks. Your comment is very useful to me.

how to provide proxy server details (host/username/password) in this script?

For you jscripties out there, I optimized this for jscript here:

OdeV66 commented Nov 13, 2017

Hi, when running the VBS I'm getting 'Invalid URL', while in fact, it isn't? Literally copying that into the browser does get me to that file/page.
Any ideas please?

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