Sample code for 30+ languages & platforms
Tcl

Create an FTP Upload Plan

See more FTP Examples

Demonstrates the Chilkat Ftp2.CreatePlan method, which creates and returns a textual upload plan for a local directory. The only argument is the local directory. The object must be connected, because the plan records the current absolute remote directory together with the local source paths.

Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A plan is a saved, resumable description of an upload — the list of local files and their absolute remote destinations — computed once and executed later (or on another run) with PutPlan. Separating planning from execution suits large or unreliable transfers: the plan can be reviewed, stored, and re-run, and because it records absolute remote paths it stays correct even if the working directory later changes.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Ftp2.CreatePlan method, which creates and returns a textual upload plan for a
#  local directory.  The only argument is the local directory.  The object must be connected,
#  because the plan records the current absolute remote directory.

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
}

#  The plan captures which local files to upload and the absolute remote destination.  Save it so
#  the upload can be run (or resumed) later with PutPlan.
set plan [CkFtp2_createPlan $ftp "qa_data/site"]
if {[CkFtp2_get_LastMethodSuccess $ftp] == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

#  Persist the plan text for later use.
set sbPlan [new_CkStringBuilder]

CkStringBuilder_Append $sbPlan $plan
set success [CkStringBuilder_WriteFile $sbPlan "qa_output/upload_plan.txt"]
if {$success == 0} then {
    puts [CkStringBuilder_lastErrorText $sbPlan]
    delete_CkFtp2 $ftp
    delete_CkStringBuilder $sbPlan
    exit
}

puts "Upload plan created."

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


delete_CkFtp2 $ftp
delete_CkStringBuilder $sbPlan