Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatFtp2)) To hoFtp
    If (Not(IsComObjectCreated(hoFtp))) Begin
        Send CreateComObject of hoFtp
    End

    Set ComHostname Of hoFtp To "ftp.example.com"
    Set ComUsername Of hoFtp To "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.
    Set ComPassword Of hoFtp To "myPassword"

    //  Use explicit FTPS (AUTH TLS) on the standard FTP port.
    Set ComAuthTls Of hoFtp To True

    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  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.
    Get ComClearControlChannel Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Control channel reverted to clear text."

    Get ComDisconnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure