Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp
integer li_Mode
oleobject loo_Synced
integer n
integer i
string ls_RelPath

li_Success = 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.

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.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.
loo_Ftp.Password = "myPassword"

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Perform a sync.
li_Mode = 6
li_Success = loo_Ftp.SyncLocalTree("qa_output/site",li_Mode)
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Get the list of files that were uploaded, downloaded, or deleted by that sync.
loo_Synced = create oleobject
li_rc = loo_Synced.ConnectToNewObject("Chilkat.StringTable")

loo_Ftp.GetSyncedFiles(loo_Synced)

n = loo_Synced.Count
Write-Debug "Affected files: " + string(n)

for i = 0 to n - 1
    ls_RelPath = loo_Synced.StringAt(i)
    if loo_Synced.LastMethodSuccess = 0 then
        Write-Debug loo_Synced.LastErrorText
        destroy loo_Ftp
        destroy loo_Synced
        return
    end if

    Write-Debug ls_RelPath
next

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    destroy loo_Synced
    return
end if



destroy loo_Ftp
destroy loo_Synced