Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
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 Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ftp2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
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 := TFtp2.Create;
ftp.Hostname := 'ftp.example.com';
ftp.Port := 21;
// Connect in clear text first (Ssl is false).
success := ftp.ConnectOnly();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Upgrade the control channel to explicit TLS (AUTH TLS).
success := ftp.ConvertToTls();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Now authenticate over the encrypted control channel.
ftp.Username := 'myFtpLogin';
ftp.Password := 'myPassword';
success := ftp.LoginAfterConnectOnly();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
WriteLn('Control channel upgraded to TLS and logged in.');
success := ftp.Disconnect();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
ftp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.