Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Use Explicit FTP over TLS

See more FTP Examples

Demonstrates how to connect to an FTP server using explicit FTP over TLS.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  ftp := TFtp2.Create;

  ftp.Hostname := 'ftp.your-ftp-server.com';
  ftp.Username := 'ftpAccountLogin';
  ftp.Password := 'ftpAccountPassword';

  //  Indicate that the "AUTH TLS" command should be use to convert the connection to TLS
  //  after the initial TCP connection to port 21 is established.
  ftp.AuthTls := True;

  //  Connect and convert the connection to TLS automatically.
  success := ftp.ConnectOnly();
  if (success <> True) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;

  success := ftp.LoginAfterConnectOnly();
  if (success <> True) then
    begin
      WriteLn(ftp.LastErrorText);
      Exit;
    end;

  WriteLn('TLS connection established and successfully authenticated.');


  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.