Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set 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.

set ftp [new_CkFtp2]

CkFtp2_put_Hostname $ftp "ftp.example.com"
CkFtp2_put_Username $ftp "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.
CkFtp2_put_Password $ftp "myPassword"

#  Use explicit FTPS (AUTH TLS) on the standard FTP port.
CkFtp2_put_AuthTls $ftp 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.
set pfxPassword "myPfxPassword"
set cert [new_CkCert]

set success [CkCert_LoadPfxFile $cert "qa_data/client.pfx" $pfxPassword]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

#  Provide the client certificate before connecting.
set success [CkFtp2_SetSslClientCert $ftp $cert]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

set success [CkFtp2_Connect $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

puts "Connected with a client certificate."

set success [CkFtp2_Disconnect $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}


delete_CkFtp2 $ftp
delete_CkCert $cert