sftp/Simple.wsf
<?xml version="1.0"?>
<package>
<job>
<reference object="sfFTPLib.SFTPConnection"/>
<script language="VBScript">
<![CDATA[
'///////////////////////////////////////////////////////////////////////////////////
'//
'// Simple v1.0 (17. December 2007)
'//
'// Purpose:
'// - Connects to remote server.
'// - Reads the current directory.
'// - Downloads a file.
'// - Uploads a file.
'//
'// Copyright (c) 2007 by SmartFTP.com
'//
'///////////////////////////////////////////////////////////////////////////////////
Dim obj
Set obj = CreateObject("sfFTPLib.SFTPConnection")
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 = "Simple.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
Dim ret
ret = obj.Connect()
If ret = ftpErrorSuccess Then
WScript.Echo "Connect() successful. RemoteId=" & obj.RemoteId & vbCrLf
' Always get the current path
ret = obj.RealPath(".")
If ret = ftpErrorSuccess Then
Dim strCurrentPath
strCurrentPath = obj.LastPath
WScript.Echo "Current Path = " & strCurrentPath & vbCrLf
' Reading the directory
ret = obj.ReadDirectory(strCurrentPath)
If ret = ftpErrorSuccess Then
Dim oItems
Set oItems = obj.Items
strMsg = strMsg & "Directory: " & strCurrentPath & " Count: " & oItems.Count & vbCrLf
Dim oItem
For Each oItem In obj.Items
strMsg = strMsg & " Type=" & oItem.Type & ", Name=" & oItem.Name & ", Size=" & oItem.SizeLo
If oItem.IsValidAttribute(ftpSFTPItemAttributeModifyTime) Then
strMsg = strMsg & ", ModifyTime=" & CDate(oItem.ModifyTimeAsDate)
End if
strMsg = strMsg & vbCrLf
Next
WScript.Echo strMsg
Else
WScript.Echo "ReadDirectory() failed. Error = " & ret & vbCrLf
End If
' 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
If obj.DownloadFile(strRemoteFile, strLocalFile, 0,0, 0,0) = ftpErrorSuccess Then
WScript.Echo """" & strRemoteFile & """ successfully downloaded to """ & strLocalFile & """" & vbCrLf
' Stat. Trying to get file size
If obj.Stat(strRemoteFile, ftpSFTPItemAttributeSize) = ftpErrorSuccess Then
' TODO: Use IsValidAttribute to check if the Size attribute is valid.
WScript.Echo "File Size = " & obj.LastItem.SizeLo
End If
Else
WScript.Echo "Failed to download """ & strRemoteFile & """ to """ & strLocalFile & """" & vbCrLf
End If
' 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
If obj.UploadFile(strLocalFile, strRemoteFile, 0,0, 0,0) = ftpErrorSuccess Then
WScript.Echo """" & strLocalFile & """ successfully uploaded to """ & strRemoteFile & """" & vbCrLf
Else
WScript.Echo "Failed to upload """ & strLocalFile & """ to """ & strRemoteFile & """" & vbCrLf
End If
End If
Else
WScript.Echo "Connect() failed. Error = " & ret & vbCrLf
End If
]]>
</script>
</job>
</package>