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";

var sshFileLogger = new ActiveXObject("sfFTPLib.FileLogger");
sshFileLogger.File = ".\\ssh.log";
obj.Logger = sshFileLogger;

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

var fileLogger = new ActiveXObject("sfFTPLib.FileLogger");
fileLogger.File = ".\\sftp.log";
objSFTP.Logger = fileLogger;

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();