Sample code for 30+ languages & platforms
Delphi DLL

Upgrade an FTP Control Channel to TLS (ConvertToTls)

See more FTP Examples

Demonstrates the Chilkat Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control channel to explicit TLS. It takes no arguments and is used with a manually staged connection created by ConnectOnly while Ssl is disabled.

Background: This exposes the explicit-FTPS AUTH TLS upgrade as a discrete step for the rare case where you need to do something on the clear connection first — inspect the greeting, apply a workaround — before securing it. In the normal case you simply set AuthTls and let Connect perform the upgrade automatically; this manual path exists for staged control.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
ftp: HCkFtp2;

begin
success := False;

//  Demonstrates the Ftp2.ConvertToTls method, which upgrades an already-connected clear FTP control
//  channel to explicit TLS.  It takes no arguments.  It is used with a manually staged connection
//  created by ConnectOnly while Ssl is disabled.

ftp := CkFtp2_Create();

CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putPort(ftp,21);

//  Connect in clear text first (Ssl is false).
success := CkFtp2_ConnectOnly(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

//  Upgrade the control channel to explicit TLS (AUTH TLS).
success := CkFtp2_ConvertToTls(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

//  Now authenticate over the encrypted control channel.
CkFtp2_putUsername(ftp,'myFtpLogin');
CkFtp2_putPassword(ftp,'myPassword');
success := CkFtp2_LoginAfterConnectOnly(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;
Memo1.Lines.Add('Control channel upgraded to TLS and logged in.');

success := CkFtp2_Disconnect(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

CkFtp2_Dispose(ftp);