Note that the documentation covers new features and changes in beta releases 4.2 through 4.2.4 already.

Downloading file to timestamped-filename

You may use following Windows script host JavaScript code (example.js):

// Local path to download to (keep trailing slash)
var LOCALPATH = ".\\";
// Remote path to download from (keep trailing slash)
var REMOTEPATH = "/";
// File to download
var FILE = "winscp421.exe";
// Session to connect to
var SESSION = "test@127.0.0.1";
// Path to winscp.com
var WINSCP = "c:\\program files\\winscp\\winscp.com";
 
// helper function to pad zeroes to the left of number
function pad(n, len)
{
    var s = n.toString();
    while (s.length < len)
    {
        s = '0' + s;
    }
    return s;
}
 
var date = new Date();
 
// format timestamp
var stamp = 
    pad(date.getFullYear(), 4) +
    pad(date.getMonth(), 2) +
    pad(date.getDate(), 2) +
    pad(date.getHours(), 2) +
    pad(date.getMinutes(), 2) +
    pad(date.getSeconds(), 2);
 
var shell = WScript.CreateObject("WScript.Shell");
 
// run winscp to get list of file in the remote directory into XML log
exec = shell.Exec("\"" + WINSCP + "\"");
exec.StdIn.Write(
    "option batch abort\n" +
    "open \"" + SESSION + "\"\n" +
    "get \"" + REMOTEPATH + FILE + "\" \"" + LOCALPATH + FILE + "." + stamp + "\"\n" +
    "exit\n");
 
// wait until the script finishes
while (!exec.StdOut.AtEndOfStream)
{
    WScript.Echo(exec.StdOut.ReadAll());
}

Run the script with command:

cscript /nologo example.js

Further Reading

 
  scripts.txt · Last modified: 12 Sep 2009 by prikryl
 

Search

This page

Donate

Donate via PayPal

Associations

Site design by Black Gate