sftp/Simple.js

///////////////////////////////////////////////////////////////////////////////////
//
// Simple
//
// Purpose: 
//   Connects to remote server.
//
// Technical support: support@smartftp.com
//
///////////////////////////////////////////////////////////////////////////////////
var objGlobal = new ActiveXObject("sfFTPLib.Global");
//objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");

var obj = new ActiveXObject("sfFTPLib.SSHConnection");

// Settings
obj.Host = "localhost";
obj.Port = 22;
obj.Username = "yourusername";
obj.Password = "yourpassword";

//var sshFileLogger = obj.SetFileLogger();
//sshFileLogger.File = ".\\ssh.log";

// Connect
obj.Connect();
WScript.Echo("SSH Connected");	
var objSFTP = obj.CreateSFTPConnection();

//var fileLogger = objSFTP.SetFileLogger();
//fileLogger.File = ".\\sftp.log";

objSFTP.Connect();	

var currentPath = objSFTP.RealPath(".");
var oItems = objSFTP.ReadDirectory(currentPath);

var message = "";
for (var fc = new Enumerator(oItems); !fc.atEnd(); fc.moveNext())
{
	var item = fc.item();
	message += " Type=" + item.Type + ", Name=" + item.Name + ", Date=" + item.ModifyTimeAsDate + "\r\n";
	if(item.Type == 1 /*ftpItemTypeRegularFile*/)
	{
		message += ", Size=" + item.SizeLo;
	}
}
WScript.Echo(message);

// TODO: change paths
var remoteFile = "/C/Archive/date.zip";
var localFile = "Download\\date.zip";
objSFTP.DownloadFile(remoteFile, localFile, 2 /*ftpDataTransferTypeImage*/, 0, 0);

obj.Disconnect();