// Function to figure out the date of the previous business day
// in the format YYYYMMDD including place holding zeros.
function PreviousBizDay() {
function D2( val ) {
return ( ( val < 10 ) ? '0' : '' ) + val;
}
var today = new Date();
today.setDate( today.getDate() - 1 ); // Yesterday...
while ( ( today.getDay() < 1 ) || ( today.getDay() > 5 ) ) {
today.setDate( today.getDate() - 1 ); // Previous day
}
return today.getFullYear() + D2( today.getMonth() + 1 ) + D2( today.getDate() )
}
// Local path to download to (MUST keep trailing slashes)
var LOCALPATH = "d:\\logs\\";
// Remote path to search in (MUST keep trailing slash)
var REMOTEPATH = "/var/spool/monitor";
// Session to connect to
var SESSION = "root:
[email protected]";
// Path to winscp.com (MUST keep trailing slashes)
var WINSCP = "c:\\program files\\winscp\\winscp.com";
var filesys = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
var FILE1 = "file." + PreviousBizDay() + ".".txt";
var exec;
// Run WINSCP and download the 3 files, then exit
exec = shell.Exec("\"" + WINSCP + "\"");
exec.StdIn.Write(
"option batch abort\n" +
"option confirm off\n" +
"open \"" + SESSION + "\"\n" +
"get \"" + REMOTEPATH + FILE1 + "\" \"" + LOCALPATH + "\"\n" +
"exit\n");