Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

set ftp [new_CkFtp2]

CkFtp2_put_Hostname $ftp "ftp.example.com"

# If using implicit TLS, you probably want port 990..
CkFtp2_put_Port $ftp 990

# Set this to 0 for implicit TLS, otherwise set to 1 for explicit TLS (where port is typically 21).
CkFtp2_put_AuthTls $ftp 0

# Set this to 1 for implicit TLS, otherwise set to 0.
CkFtp2_put_Ssl $ftp 1

set cert [new_CkCert]

set success [CkCert_LoadByCommonName $cert "The common name of your certificate"]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

# Use this certificate for our TLS mutually authenticated connection:
set success [CkFtp2_SetSslClientCert $ftp $cert]
if {$success == 0} then {
    puts [CkCert_lastErrorText $cert]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

# Establish the TLS connection with the FTP server.
set success [CkFtp2_ConnectOnly $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

# If a login is required, then login with the FTP account login/password.
CkFtp2_put_Username $ftp "myLogin"
CkFtp2_put_Password $ftp "myPassword"
set success [CkFtp2_LoginAfterConnectOnly $ftp]
if {$success == 0} then {
    puts [CkFtp2_lastErrorText $ftp]
    delete_CkFtp2 $ftp
    delete_CkCert $cert
    exit
}

# Do whatever you're doing to do ...
# upload files, download files, etc...

# .....
# .....

set success [CkFtp2_Disconnect $ftp]

delete_CkFtp2 $ftp
delete_CkCert $cert