Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set 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.

set ftp [new_CkFtp2]

CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "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.
CkFtp2_put_Password $ftp "myPassword"

set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

set success [CkFtp2_ChangeRemoteDir $ftp "public_html"]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

#  Perform a sync.
set mode 6
set success [CkFtp2_SyncLocalTree $ftp "qa_output/site" $mode]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

#  Get the list of files that were uploaded, downloaded, or deleted by that sync.
set synced [new_CkStringTable]

CkFtp2_GetSyncedFiles $ftp $synced

set n [CkStringTable_get_Count $synced]
puts "Affected files: $n"

for {set i 0} {$i <= [expr $n - 1]} {incr i} {
    set relPath [CkStringTable_stringAt $synced $i]
    if {[CkStringTable_get_LastMethodSuccess $synced] == 0} then {
        puts [CkStringTable_lastErrorText $synced]
        delete_CkFtp2 $ftp
        delete_CkStringTable $synced
        exit
    }

    puts "$relPath"
}

set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkStringTable $synced
    exit
}


delete_CkFtp2 $ftp
delete_CkStringTable $synced