Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

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

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "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.
loo_Ftp.Password = "myPassword"

//  Use explicit FTPS (AUTH TLS) on the standard FTP port.
loo_Ftp.AuthTls = 1

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  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.
li_Success = loo_Ftp.ClearControlChannel()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Control channel reverted to clear text."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp