PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Sftp
integer li_Port
integer li_IncludeKeyType
integer li_IncludeHashName
string ls_Fingerprint
li_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.
loo_Sftp = create oleobject
li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp")
if li_rc < 0 then
destroy loo_Sftp
MessageBox("Error","Connecting to COM object failed")
return
end if
// Step 1: Connect the SSH transport. Port 22 is the usual port.
li_Port = 22
li_Success = loo_Sftp.Connect("sftp.example.com",li_Port)
if li_Success = 0 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
// Get the SHA256 fingerprint, including the key type and hash name.
li_IncludeKeyType = 1
li_IncludeHashName = 1
ls_Fingerprint = loo_Sftp.GetHostKeyFP("SHA256",li_IncludeKeyType,li_IncludeHashName)
if loo_Sftp.LastMethodSuccess = 0 then
Write-Debug loo_Sftp.LastErrorText
destroy loo_Sftp
return
end if
Write-Debug "Host key fingerprint: " + ls_Fingerprint
loo_Sftp.Disconnect()
destroy loo_Sftp