Sample code for 30+ languages & platforms
Objective-C

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 Objective-C Downloads

Objective-C
#import <CkoFtp2.h>

BOOL success = NO;

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

CkoFtp2 *ftp = [[CkoFtp2 alloc] init];

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

//  Use explicit FTPS (AUTH TLS) on the standard FTP port.
ftp.AuthTls = YES;

success = [ftp Connect];
if (success == NO) {
    NSLog(@"%@",ftp.LastErrorText);
    return;
}

//  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.
success = [ftp ClearControlChannel];
if (success == NO) {
    NSLog(@"%@",ftp.LastErrorText);
    return;
}

NSLog(@"%@",@"Control channel reverted to clear text.");

success = [ftp Disconnect];
if (success == NO) {
    NSLog(@"%@",ftp.LastErrorText);
    return;
}