Skip to content

Instantly share code, notes, and snippets.

@bitnetwork bitnetwork/wget.js forked from udawtr/wget.vbs
Last active Mar 22, 2020

Embed
What would you like to do?
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

This comment has been minimized.

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
You can’t perform that action at this time.