Xojo Plugin
Xojo Plugin
Get the Files Transferred by an SFTP Sync
See more SFTP Examples
Demonstrates the Chilkat SFtp.GetSyncedFiles method, which reports the relative paths processed by the most recent SyncTreeUpload or SyncTreeDownload. The only argument is a StringTable that receives the paths. Directory paths end with / so they can be distinguished from files.
Note: This example uses relative local paths, which are resolved against the application's current working directory. Absolute local paths may also be used. Supply the paths appropriate to your own environment.
Background: A sync call reports only overall success, but you usually want to know what actually changed — for logging, for triggering follow-up work on just the new files, or simply to confirm an incremental sync did the minimal transfer. This method provides that list after the fact. An empty result is meaningful too: it means everything was already up to date. Call it immediately after the sync, before another operation replaces the recorded list.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Demonstrates the SFtp.GetSyncedFiles method, which reports the relative paths processed by the
// most recent SyncTreeUpload or SyncTreeDownload. The only argument is a StringTable that
// receives the paths.
Dim sftp As New Chilkat.SFtp
// Connect, authenticate, and initialize the SFTP subsystem.
Dim port As Int32
port = 22
success = sftp.Connect("sftp.example.com",port)
If (success = False) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
Dim password As String
password = "mySshPassword"
success = sftp.AuthenticatePw("mySshLogin",password)
If (success = False) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
success = sftp.InitializeSftp()
If (success = False) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
// Perform a sync.
Dim mode As Int32
mode = 5
Dim recurse As Boolean
recurse = True
success = sftp.SyncTreeDownload("/var/www/html","qa_output/website",mode,recurse)
If (success = False) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
// Get the list of files (and, for downloads, directories) that were actually transferred.
// Directory paths end with "/" so they can be told apart from file paths.
Dim synced As New Chilkat.StringTable
sftp.GetSyncedFiles synced
Dim n As Int32
n = synced.Count
System.DebugLog("Synced " + Str(n) + " item(s):")
Dim i As Int32
For i = 0 To n - 1
Dim relPath As String
relPath = synced.StringAt(i)
If (synced.LastMethodSuccess = False) Then
System.DebugLog(synced.LastErrorText)
Return
End If
System.DebugLog(relPath)
Next
sftp.Disconnect