Ruby
Ruby
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 Ruby Downloads
require 'chilkat'
success = false
# 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.
ftp = Chilkat::CkFtp2.new()
ftp.put_Hostname("ftp.example.com")
ftp.put_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.
ftp.put_Password("myPassword")
success = ftp.Connect()
if (success == false)
print ftp.lastErrorText() + "\n";
exit
end
success = ftp.ChangeRemoteDir("public_html")
if (success == false)
print ftp.lastErrorText() + "\n";
exit
end
# Perform a sync.
mode = 6
success = ftp.SyncLocalTree("qa_output/site",mode)
if (success == false)
print ftp.lastErrorText() + "\n";
exit
end
# Get the list of files that were uploaded, downloaded, or deleted by that sync.
synced = Chilkat::CkStringTable.new()
ftp.GetSyncedFiles(synced)
n = synced.get_Count()
print "Affected files: " + n.to_s() + "\n";
for i in 0 .. n - 1
relPath = synced.stringAt(i)
if (synced.get_LastMethodSuccess() == false)
print synced.lastErrorText() + "\n";
exit
end
print relPath + "\n";
end
success = ftp.Disconnect()
if (success == false)
print ftp.lastErrorText() + "\n";
exit
end