sftp/Simple.ps1

#########################################################
# 
# Summary: 
# This script demonstrates the following features:
# - Connect
# - Download of file
# - Read drectory (enumeration)
# - Disconnect
#
# Notes:
# If you get the following error:
# "cannot be loaded because the execution of scripts is disabled on this system."
# Enable the execution of scripts:
# Set-ExecutionPolicy RemoteSigned
#
# Technical support: support@smartftp.com
#
# Copyright (c) by SmartSoft Ltd.
#########################################################

# If you want to use the interop assembly (you need to create it first) use:
# [Reflection.Assembly]::LoadWithPartialname("Interop.sfFTPLib") | out-null
# For more information: http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan09/hey0126.mspx

# Creates new COM object
$ssh = new-object -com sfFTPLib.SSHConnection;
$ssh.Host = "host";
$ssh.Port = 22; 
$ssh.Username = "user";
$ssh.Password = "password";
# $ssh.LogFile.File = "C:\test.log";

$ssh.Connect();
Write-Host "Connected";
	
$sftp  = $ssh.CreateSFTPConnection();	
$sftp.Connect();

Write-Host "SFTP channel opened";

# gets current directory
$home = $sftp.RealPath(".");
Write-Host ("RealPath succeeded. Home={0}" -f $home)
	
foreach($item in $sftp.ReadDirectory($home))
{
	Write-Host ("Name={0}, Type={1}, Size={2}, ModifyTime={3}" -f $item.Name, $item.Type, $item.Size, [System.DateTime]::FromOADate($item.ModifyTimeAsDate).ToString("o"))
}
			
# Use the absolute path to the source file
$sftp.DownloadFileEx("/License.txt", "License.txt", 0, 0);
Write-Host "DownloadFile succeeded"
$ssh.Disconnect();