wget.js - similar to wget but written in jscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//wget.js - similar to wget but written in vbscript | |
//based on a script by Chrissy LeMaire | |
//forked by Bit | |
var shell = new ActiveXObject("WScript.shell"); | |
//Usage | |
if (WScript.Arguments.length < 1) { | |
shell.Popup("Usage: wget.js <url> (file)"); | |
WScript.Quit(); | |
} | |
//Arguments | |
var url = WScript.Arguments(0); | |
if (WScript.Arguments.length > 1) { | |
var saveTo = WScript.Arguments(1); | |
} else { | |
parts = url.split("/"); | |
var saveTo = parts.slice(0, parts.length - 1); | |
} | |
//Fetch the file | |
var xhr = new ActiveXObject("MSXML2.ServerXMLHTTP"); | |
xhr.open("GET", url, false); | |
xhr.send(); | |
if (xhr.status === 200) { | |
var stream = new ActiveXObject("ADODB.Stream"); | |
stream.Open(); | |
stream.Type = 1; //adTypeBinary | |
stream.Write(xhr.responseBody); | |
stream.Position = 0; //Set the stream position to the start | |
var explorer = new ActiveXObject("Scripting.FileSystemObject"); | |
if (explorer.Fileexists(saveTo)) { explorer.DeleteFile(saveTo); } | |
stream.SaveToFile(saveTo); | |
stream.Close(); | |
} | |
//Done | |
WScript.Quit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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