sftp/Simple.js

///////////////////////////////////////////////////////////////////////////////////
//
// Simple
//
// Purpose: 
//   Connects to remote server.
//
// Technical support: support@smartftp.com
//
// Copyright (c) by SmartSoft Ltd.
//
///////////////////////////////////////////////////////////////////////////////////
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";
obj.LogFile.File = ".\\ssh.log";

// Connect
obj.Connect();
WScript.Echo("SSH Connected");	
var objSFTP = obj.CreateSFTPConnection();
objSFTP.LogFile.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, 0,0);

obj.Disconnect();