Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loFtp
LOCAL lnMode
LOCAL loSynced
LOCAL n
LOCAL i
LOCAL lcRelPath
lnSuccess = 0
* 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.
loFtp = CreateObject('Chilkat.Ftp2')
loFtp.Hostname = "ftp.example.com"
loFtp.Username = "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.
loFtp.Password = "myPassword"
lnSuccess = loFtp.Connect()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
lnSuccess = loFtp.ChangeRemoteDir("public_html")
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
* Perform a sync.
lnMode = 6
lnSuccess = loFtp.SyncLocalTree("qa_output/site",lnMode)
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
CANCEL
ENDIF
* Get the list of files that were uploaded, downloaded, or deleted by that sync.
loSynced = CreateObject('Chilkat.StringTable')
loFtp.GetSyncedFiles(loSynced)
n = loSynced.Count
? "Affected files: " + STR(n)
FOR i = 0 TO n - 1
lcRelPath = loSynced.StringAt(i)
IF (loSynced.LastMethodSuccess = 0) THEN
? loSynced.LastErrorText
RELEASE loFtp
RELEASE loSynced
CANCEL
ENDIF
? lcRelPath
NEXT
lnSuccess = loFtp.Disconnect()
IF (lnSuccess = 0) THEN
? loFtp.LastErrorText
RELEASE loFtp
RELEASE loSynced
CANCEL
ENDIF
RELEASE loFtp
RELEASE loSynced