Sample code for 30+ languages & platforms
Tcl

Change the Remote Directory (CWD)

See more FTP Examples

Demonstrates the Chilkat Ftp2.ChangeRemoteDir method, which changes the current working directory on the FTP server. The only argument is the remote directory path.

Background: This sends a single CWD with the path exactly as given; Chilkat does not split a multi-level path into one CWD per segment, so whether a/b/c works in one call depends on the server. A relative path moves from the current directory, while an absolute path (leading /) is resolved from the root according to the server's conventions. Confirm the result with GetCurrentRemoteDir when it matters.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Ftp2.ChangeRemoteDir method, which changes the current working directory on
#  the FTP server.  The only argument is the remote directory path.

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"

#  Connect and log in (Connect performs both).
set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

#  A relative path is resolved from the current remote directory; an absolute path (beginning
#  with "/") is interpreted according to the server's path syntax.
set success [CkFtp2_ChangeRemoteDir $ftp "public_html/images"]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

set currentDir [CkFtp2_getCurrentRemoteDir $ftp]
if {[CkFtp2_get_LastMethodSuccess $ftp] == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

puts "Now in: $currentDir"

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


delete_CkFtp2 $ftp