Xbase++
Xbase++
FTPS with Client Cert from Windows Certificate Store
See more FTP Examples
Demonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oFtp
LOCAL oCert
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oFtp := CreateObject("Chilkat.Ftp2")
oFtp:Hostname := "ftp.example.com"
// If using implicit TLS, you probably want port 990..
oFtp:Port := 990
// Set this to 0 for implicit TLS, otherwise set to 1 for explicit TLS (where port is typically 21).
oFtp:AuthTls := 0
// Set this to 1 for implicit TLS, otherwise set to 0.
oFtp:Ssl := 1
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadByCommonName("The common name of your certificate")
IF (nSuccess == 0)
? oCert:LastErrorText
oFtp:destroy()
oCert:destroy()
RETURN
ENDIF
// Use this certificate for our TLS mutually authenticated connection:
nSuccess := oFtp:SetSslClientCert(oCert)
IF (nSuccess == 0)
? oCert:LastErrorText
oFtp:destroy()
oCert:destroy()
RETURN
ENDIF
// Establish the TLS connection with the FTP server.
nSuccess := oFtp:ConnectOnly()
IF (nSuccess == 0)
? oFtp:LastErrorText
oFtp:destroy()
oCert:destroy()
RETURN
ENDIF
// If a login is required, then login with the FTP account login/password.
oFtp:Username := "myLogin"
oFtp:Password := "myPassword"
nSuccess := oFtp:LoginAfterConnectOnly()
IF (nSuccess == 0)
? oFtp:LastErrorText
oFtp:destroy()
oCert:destroy()
RETURN
ENDIF
// Do whatever you're doing to do ...
// upload files, download files, etc...
// .....
// .....
nSuccess := oFtp:Disconnect()
oFtp:destroy()
oCert:destroy()