i\'m trying to automate a file download with Windows Script Host (JScript). i see ADODB.Stream has an Open method whose documentation makes it seem like it should be possible t
Converted the above code to JavaScript. This appears to work for me. Recommend adding a try catch block to the caller. Also, converted to async. I've used this code to save some 90 files at the same time. Since the delete file (necessary as the overwrite fails) is synchronous, it is better moved to a separate function for multiple files.
function saveFile(sSourceUrl, sDestFile) {
var objXMLHTTP = new ActiveXObject("MSXML2.XMLHTTP");
objXMLHTTP.onreadystatechange=function() {
if (objXMLHTTP.readyState === 4) {
var objADOStream = new ActiveXObject("ADODB.Stream");
objADOStream.open();
objADOStream.type = 1; // Binary
objADOStream.write(objXMLHTTP.ResponseBody);
objADOStream.position = 0;
objADOStream.saveToFile(sDestFile, 2);
objADOStream.close();
}
};
objXMLHTTP.open("GET", sSourceUrl, false);
objXMLHTTP.send();
}