Download *.ppm file from the Web?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Download *.ppm file from the Web?

#1 Post by SIMMS7400 » 06 Apr 2017 13:56

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!


aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Download *.ppm file from the Web?

#3 Post by aGerman » 07 Apr 2017 11:51

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

SIMMS7400
Posts: 544
Joined: 07 Jan 2016 07:47

Re: Download *.ppm file from the Web?

#4 Post by SIMMS7400 » 10 Apr 2017 01:26

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!!

Post Reply