Page 1 of 1
Download *.ppm file from the Web?
Posted: 06 Apr 2017 13:56
by SIMMS7400
Hi Folks -
In an effort automate some of my processes, I particularly want to be able to download a file from the web.
This file is a *.ppm file located at this path:
https://www.manageengine.com/products/service-desk/service-packs.html
I always want to load the in the right most pane, labeled "Service pack".
Is this dooable with batch?
Thanks!
Re: Download *.ppm file from the Web?
Posted: 06 Apr 2017 15:38
by npocmaka_
Re: Download *.ppm file from the Web?
Posted: 07 Apr 2017 11:51
by aGerman
Either use 3rd party tools or a hybrid script like that
Code: Select all
@if (@a)==(@b) @end /* Batch part:
@echo off &setlocal
cscript //nologo //e:jscript "%~fs0" "%userprofile%\Desktop"
pause
exit /b
JScript Part : */
var objIE = null;
try {
WScript.Echo('Searching link ...');
objIE = new ActiveXObject('InternetExplorer.Application');
// objIE.Visible = true;
objIE.Navigate('https://www.manageengine.com/products/service-desk/service-packs.html');
while (objIE.Busy) { WScript.Sleep(100); }
var link = objIE.document.getElementsByClassName('box-table mT20')[0].getElementsByTagName('tr')[2].getElementsByTagName('td')[2].getElementsByTagName('a')[0].getAttribute('href');
objIE.Quit();
objIE = null;
WScript.Echo('Found: ' + link);
WScript.Echo('Downloading ...');
var objXMLHTTP = new ActiveXObject('MSXML2.ServerXMLHTTP');
objXMLHTTP.open('GET', link, false);
objXMLHTTP.send();
var objADOStream = new ActiveXObject('ADODB.Stream');
objADOStream.Type = 1;
objADOStream.Mode = 3;
objADOStream.Open();
objADOStream.Write(objXMLHTTP.responseBody);
objADOStream.Position = 0;
WScript.Echo('Saving ...');
var objFSO = new ActiveXObject('Scripting.FileSystemObject');
objADOStream.SaveToFile(objFSO.BuildPath(WScript.Arguments(0), objFSO.GetFileName(link)), 2);
objADOStream.Close();
}
catch(e) {
if (objIE != null) { objIE.Quit(); }
WScript.Echo('Error!');
}
The argument passed is the path where you want to save the file (the user's desktop in this case). It takes quite a while to download the file (which seems to be rather an issue of the web site than of the script).
Steffen
Re: Download *.ppm file from the Web?
Posted: 10 Apr 2017 01:26
by SIMMS7400
Wow - thank you both!!!
The JScript solution is EXPONENTIALLY faster. Downloading the file manually when compared to JScript solution, there's not much difference.
Thank you again!!