Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Ftp2, Cert;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
ftp: HCkFtp2;
cert: HCkCert;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := CkFtp2_Create();
CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putPort(ftp,21);
// If using implicit TLS, you probably want port 990..
CkFtp2_putPort(ftp,990);
// Set this to False for implicit TLS, otherwise set to True for explicit TLS (where port is typically 21).
CkFtp2_putAuthTls(ftp,False);
// Set this to True for implicit TLS, otherwise set to False.
CkFtp2_putSsl(ftp,True);
cert := CkCert_Create();
success := CkCert_LoadPfxFile(cert,'qa_data/pfx/example.pfx','pfx_password');
if (success = False) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
// Use this certificate for our TLS mutually authenticated connection:
success := CkFtp2_SetSslClientCert(ftp,cert);
if (success = False) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
// Establish the TLS connection with the FTP server.
success := CkFtp2_ConnectOnly(ftp);
if (success = False) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
// If a login is required, then login with the FTP account login/password.
CkFtp2_putUsername(ftp,'myLogin');
CkFtp2_putPassword(ftp,'myPassword');
success := CkFtp2_LoginAfterConnectOnly(ftp);
if (success = False) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
// Do whatever you're doing to do ...
// upload files, download files, etc...
// .....
// .....
success := CkFtp2_Disconnect(ftp);
CkFtp2_Dispose(ftp);
CkCert_Dispose(cert);
end;