sftp/Simple.wsf

<?xml version="1.0"?>
<package>

<job>
<reference object="sfFTPLib.SFTPConnection"/>
<reference object="sfFTPLib.SSHConnection"/>
<script language="VBScript">
<![CDATA[

'///////////////////////////////////////////////////////////////////////////////////
'//
'// Simple
'//
'// Purpose: 
'// - Connects to remote server. 
'// - Reads the current directory. 
'// - Downloads a file.
'// - Uploads a file.
'//
'// Technical support: support@smartftp.com
'//
'// Copyright (c) by SmartSoft Ltd.
'//
'///////////////////////////////////////////////////////////////////////////////////
Dim objGlobal
Set objGlobal = CreateObject("sfFTPLib.Global")
'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

Dim obj
Set obj = CreateObject("sfFTPLib.SSHConnection")

WScript.Echo "SFTPConnection object created." & vbCrLf

' Settings
WScript.Echo "Please change the settings in the script for this demo." & vbCrLf
obj.Host = "localhost"
obj.Username = "user"
obj.Password = "password"
obj.Port = 22

' Enable logging
obj.LogFile.File = "ssh.log"

' Public Key Authentication
' Uncomment to load private key
'Dim oKeyManager
'Set oKeyManager = CreateObject("sfFTPLib.KeyManager")
'Dim oPrivateKey
'Set oPrivateKey = oKeyManager.LoadFile("Identity", "password")
'obj.PrivateKey = oPrivateKey

' Set Authenciation Methods
' Uncomment to set authentication methods
Dim arAuthentications(1)
arAuthentications(0) = ftpSSHAuthenticationPassword
arAuthentications(1) = ftpSSHAuthenticationPublicKey
'obj.Authentications = arAuthentications
			
' Limit Encryptions
' Uncomment to limit encryptions
Dim arEncryptions(3)
arEncryptions(0) = ftpEncryption3DES
arEncryptions(1) = ftpEncryptionAES256
arEncryptions(2) = ftpEncryptionAES192
arEncryptions(3) = ftpEncryptionAES128
'obj.Encryptions = arEncryptions

' Limit Compression Algorithms
Dim arCompressions(2)
arCompressions(0) = ftpSSHCompressionzlibopenssh
arCompressions(1) = ftpSSHCompressionzlib
arCompressions(2) = ftpSSHCompressionNone
'obj.Compressions = arCompressions

obj.Connect()
WScript.Echo "Connect() successful. RemoteId=" & obj.ServerState.RemoteId & vbCrLf
objSFTP.LogFile.File = "sftp.log"

Dim objSFTP
Set objSFTP = obj.CreateSFTPConnection()
	
objSFTP.Connect()
' Always get the current path
Dim strCurrentPath
strCurrentPath = objSFTP.RealPath(".")
WScript.Echo "Current Path = " & strCurrentPath & vbCrLf		
		
' Reading the directory
Dim oItems
Set oItems = objSFTP.ReadDirectory(strCurrentPath)
strMsg = strMsg & "Directory: " & strCurrentPath & " Count: " & oItems.Count & vbCrLf
					
Dim oItem
For Each oItem In oItems
	strMsg = strMsg & " Type=" & oItem.Type & ", Name=" & oItem.Name
	If oItem.Type = ftpItemTypeRegularFile Then
		strMsg = strMsg & ", Size=" & oItem.SizeLo
	End If
	If oItem.IsValidAttribute(ftpFTPItemAttributeModifyTime) Then
		strMsg = strMsg & ", ModifyTime=" & CDate(oItem.ModifyTimeAsDate)
	End If
	strMsg = strMsg & vbCrLf
Next
				
WScript.Echo strMsg
			
' Downloading a file
Dim strRemoteFile
strRemoteFile = "/C/Archive/date.zip"
Dim strLocalFile
strLocalFile = "Download\date.zip"
WScript.Echo "Please change the paths in the script for the DownloadFile demo." & vbCrLf
call objSFTP.DownloadFile(strRemoteFile, strLocalFile, 0,0)
WScript.Echo """" & strRemoteFile & """ successfully downloaded to """ & strLocalFile & """" & vbCrLf
	
' Stat. Trying to get file size
Set oItem = objSFTP.Stat(strRemoteFile, ftpSFTPItemAttributeSize)
' TODO: Use IsValidAttribute to check if the Size attribute is valid.
WScript.Echo "File Size = " & oItem.SizeLo
			
' Uploading a file
strRemoteFile = "/C/Archive/dateupload.zip"
strLocalFile = "Download\date.zip"
WScript.Echo "Please change the paths in the script for the UploadFile demo." & vbCrLf
call objSFTP.UploadFile(strLocalFile, strRemoteFile, 0,0)
WScript.Echo """" & strLocalFile & """ successfully uploaded to """ & strRemoteFile & """" & vbCrLf

]]>
</script>
</job>

</package>