Sample code for 30+ languages & platforms
Tcl

Revert an FTPS Control Channel to Clear Text (CCC)

See more FTP Examples

Demonstrates the Chilkat Ftp2.ClearControlChannel method, which requests that an explicit-FTPS control connection return to clear text after authentication. It takes no arguments. Data connections may remain protected according to the DataProtection property.

Background: The CCC (Clear Command Channel) command exists to solve an FTPS-through-NAT problem: because FTP negotiates data ports in the control channel, a firewall or NAT device must read those commands to open the right ports — which it cannot do when the control channel is encrypted. Reverting the control channel to clear text after login lets the network device help, while the data channel can stay protected. It weakens security on the control channel, so use it only when the network requires it.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Ftp2.ClearControlChannel method, which requests that an explicit-FTPS control
#  connection return to clear text after authentication.  It takes no arguments.

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"

#  Use explicit FTPS (AUTH TLS) on the standard FTP port.
CkFtp2_put_AuthTls $ftp 1

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

#  After a secure login, revert the CONTROL channel to clear text (CCC command).  Data
#  connections may remain protected according to the DataProtection property.  This is sometimes
#  required so that NAT/firewall devices can inspect the control channel to open data ports.
set success [CkFtp2_ClearControlChannel $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    exit
}

puts "Control channel reverted to clear text."

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


delete_CkFtp2 $ftp