Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
SFTP Authentication using an SSH Certificate
See more SFTP Examples
Demonstrates how to SFTP authenticate using an SSH certificate.Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Dim sbSshCert As New Chilkat.StringBuilder
success = sbSshCert.LoadFile("qa_data/sshCert/user_ecdsa_key-cert.pub","utf-8")
If (success = False) Then
System.DebugLog("Failed to load user_ecdsa_key-cert.pub")
Return
End If
Dim sbPrivKey As New Chilkat.StringBuilder
success = sbPrivKey.LoadFile("qa_data/sshKeys/user_ecdsa_key","utf-8")
If (success = False) Then
System.DebugLog("Failed to load user_ecdsa_key")
Return
End If
Dim key As New Chilkat.SshKey
// Provide the password if the user_ecdsa_key is stored in an encrypted format.
key.Password = "secret"
success = key.FromOpenSshPrivateKey(sbPrivKey.GetAsString())
If (success = False) Then
System.DebugLog(key.LastErrorText)
Return
End If
// Indicate that the SSH certificate is to be used for authentication.
// The UseSshCertificate method was added in Chilkat v11.0.0
success = key.UseSshCertificate(sbSshCert.GetAsString())
Dim sftp As New Chilkat.SFtp
Dim hostname As String
hostname = "sftp.example.com"
Dim port As Int32
port = 22
success = sftp.Connect(hostname,port)
If (success <> True) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
success = sftp.AuthenticatePk("myLogin",key)
If (success <> True) Then
System.DebugLog(sftp.LastErrorText)
Return
End If
System.DebugLog("Public-Key Authentication using an SSH Certificate was Successful!")