DataFlex
DataFlex
Get the Files Affected by an FTP Sync
See more FTP Examples
Demonstrates the Chilkat Ftp2.GetSyncedFiles method, which reports the relative paths affected by the most recent synchronization. The only argument is a StringTable that receives the paths (uploaded, downloaded, or deleted).
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 to confirm an incremental sync did the minimal transfer. 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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoFtp
Integer iMode
Variant vSynced
Handle hoSynced
Integer n
Integer i
String sRelPath
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the Ftp2.GetSyncedFiles method, which reports the relative paths affected by the
// most recent synchronization operation. The only argument is a StringTable that receives the
// paths.
Get Create (RefClass(cComChilkatFtp2)) To hoFtp
If (Not(IsComObjectCreated(hoFtp))) Begin
Send CreateComObject of hoFtp
End
Set ComHostname Of hoFtp To "ftp.example.com"
Set ComUsername Of hoFtp To "myFtpLogin"
// 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.
Set ComPassword Of hoFtp To "myPassword"
Get ComConnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComChangeRemoteDir Of hoFtp "public_html" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// Perform a sync.
Move 6 To iMode
Get ComSyncLocalTree Of hoFtp "qa_output/site" iMode To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
// Get the list of files that were uploaded, downloaded, or deleted by that sync.
Get Create (RefClass(cComChilkatStringTable)) To hoSynced
If (Not(IsComObjectCreated(hoSynced))) Begin
Send CreateComObject of hoSynced
End
Get pvComObject of hoSynced to vSynced
Send ComGetSyncedFiles To hoFtp vSynced
Get ComCount Of hoSynced To n
Showln "Affected files: " n
For i From 0 To (n - 1)
Get ComStringAt Of hoSynced i To sRelPath
Get ComLastMethodSuccess Of hoSynced To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoSynced To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sRelPath
Loop
Get ComDisconnect Of hoFtp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoFtp To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure