Tcl
Tcl
Get the SFTP Server Host Key Fingerprint
See more SFTP Examples
Demonstrates the Chilkat SFtp.GetHostKeyFP method, which returns the connected server's host-key fingerprint. The first argument is the hash algorithm (for example SHA256 or MD5), the second controls whether the key type is included, and the third controls whether the hash name is included.
Background: The host-key fingerprint identifies the server. Comparing it against a known-good value is how a client implements host-key pinning — detecting a man-in-the-middle attempt or a changed server key before trusting the connection with credentials or files.
SHA256 is the modern default; MD5 fingerprints still appear in older tooling but are weaker.Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the SFtp.GetHostKeyFP method, which returns the server's host-key fingerprint.
# The 1st argument is the hash algorithm, the 2nd controls whether the key type is included, and
# the 3rd controls whether the hash name is included.
set sftp [new_CkSFtp]
# Step 1: Connect the SSH transport. Port 22 is the usual port.
set port 22
set success [CkSFtp_Connect $sftp "sftp.example.com" $port]
if {$success == 0} then {
puts [CkSFtp_lastErrorText $sftp]
delete_CkSFtp $sftp
exit
}
# Get the SHA256 fingerprint, including the key type and hash name.
set includeKeyType 1
set includeHashName 1
set fingerprint [CkSFtp_getHostKeyFP $sftp "SHA256" $includeKeyType $includeHashName]
if {[CkSFtp_get_LastMethodSuccess $sftp] == 0} then {
puts [CkSFtp_lastErrorText $sftp]
delete_CkSFtp $sftp
exit
}
puts "Host key fingerprint: $fingerprint"
CkSFtp_Disconnect $sftp
delete_CkSFtp $sftp