Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
FTPS with Mutual TLS Authentication (TLS Client Certificate)
See more FTP Examples
Demonstrates how to do mutual TLS authentication (using a client certificate from a .pfx/.p12).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,
Chilkat.Cert;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
cert: TCert;
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.example.com';
ftp.Port := 21;
// If using implicit TLS, you probably want port 990..
ftp.Port := 990;
// Set this to False for implicit TLS, otherwise set to True for explicit TLS (where port is typically 21).
ftp.AuthTls := False;
// Set this to True for implicit TLS, otherwise set to False.
ftp.Ssl := True;
cert := TCert.Create;
success := cert.LoadPfxFile('qa_data/pfx/example.pfx','pfx_password');
if (success = False) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
// Use this certificate for our TLS mutually authenticated connection:
success := ftp.SetSslClientCert(cert);
if (success = False) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
// Establish the TLS connection with the FTP server.
success := ftp.ConnectOnly();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// If a login is required, then login with the FTP account login/password.
ftp.Username := 'myLogin';
ftp.Password := 'myPassword';
success := ftp.LoginAfterConnectOnly();
if (success = False) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Do whatever you're doing to do ...
// upload files, download files, etc...
// .....
// .....
success := ftp.Disconnect();
ftp.Free;
cert.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.