Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bitnetwork
Forked from udawtr/wget.vbs
Last active March 22, 2020 13:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitnetwork/b6f7ef23fac1044e5dfb1187fd1936af to your computer and use it in GitHub Desktop.
Save bitnetwork/b6f7ef23fac1044e5dfb1187fd1936af to your computer and use it in GitHub Desktop.
wget.js - similar to wget but written in jscript
//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();
@Clicketyclick
Copy link

Clicketyclick commented Jun 4, 2018

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

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