Sample code for 30+ languages & platforms
Tcl

Synchronize Remote Directory Tree

See more FTP Examples

Uploads a directory tree from the local filesystem to the FTP server. Synchronization modes include:

mode=0: Upload all files
mode=1: Upload all files that do not exist on the FTP server.
mode=2: Upload newer or non-existant files.
mode=3: Upload only newer files. If a file does not already exist on the FTP server, it is not uploaded.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set ftp [new_CkFtp2]

CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "login"
CkFtp2_put_Password $ftp "password"

CkFtp2_put_KeepSessionLog $ftp 1

# Connect and login to the FTP server.
set success [CkFtp2_Connect $ftp]
if {$success != 1} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

# Set the current remote directory to the root of
# the tree where files are uploaded.
set success [CkFtp2_ChangeRemoteDir $ftp "/abc123"]
if {$success != 1} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

# Recursively upload all non-existant and newer files.
set mode 2
set success [CkFtp2_SyncRemoteTree $ftp "c:/temp/abc123" $mode]
if {$success != 1} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

set success [CkFtp2_Disconnect $ftp]

# Display the session log.  
puts [CkFtp2_sessionLog $ftp]

delete_CkFtp2 $ftp