PowerBuilder
PowerBuilder
Set an FTPS Client Certificate (Cert object)
See more FTP Examples
Demonstrates the Chilkat Ftp2.SetSslClientCert method, which configures a client certificate for FTPS servers that request mutual TLS authentication. The only argument is a Cert that must have access to its private key.
Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: Some high-security FTPS deployments require the client to present its own certificate during the TLS handshake — mutual TLS — as a second factor alongside the username and password. Because that happens while connecting, the certificate must be set before
Connect. The Cert must carry its private key, since the client proves possession of it during the handshake.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ftp
string ls_PfxPassword
oleobject loo_Cert
li_Success = 0
// Demonstrates the Ftp2.SetSslClientCert method, which configures a client certificate for FTPS
// servers that request mutual TLS authentication. The only argument is a Cert object that must
// have access to its private key.
loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
destroy loo_Ftp
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.Username = "myFtpLogin"
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
loo_Ftp.Password = "myPassword"
// Use explicit FTPS (AUTH TLS) on the standard FTP port.
loo_Ftp.AuthTls = 1
// Load the client certificate (with its private key) from a PFX file.
// The PFX password should come from a secure source rather than being hard-coded.
ls_PfxPassword = "myPfxPassword"
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/client.pfx",ls_PfxPassword)
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Ftp
destroy loo_Cert
return
end if
// Provide the client certificate before connecting.
li_Success = loo_Ftp.SetSslClientCert(loo_Cert)
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Cert
return
end if
li_Success = loo_Ftp.Connect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Cert
return
end if
Write-Debug "Connected with a client certificate."
li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
Write-Debug loo_Ftp.LastErrorText
destroy loo_Ftp
destroy loo_Cert
return
end if
destroy loo_Ftp
destroy loo_Cert