Syntax
| SFTP.AuthenticatePwPk(username As String, password As String, privateKey As ChilkatSshKey) As Long
|
---|---|
Description
| Authentication for SSH servers that require both a password and private key. (Most SSH servers are configured to require one or the other, but not both.)
Important: When reporting problems, please send the full contents of the LastErrorText property to support@tradium.nl.
Returns 1 for success, 0 for failure.
|
See Also
| |
Example
| Sub Main
' Load a private key to be used for SSH authentication.
Dim key As New ChilkatSshKey
key.Password = "key_password"
Dim success As Long
success = key.FromOpenSshPrivateKey(key.LoadText("qa_data/my_private_key_file"))
If (success <> 1) Then
Debug.Print key.LastErrorText
Exit Sub
End If
Dim sftp As New ChilkatSFtp
success = sftp.Connect("sftp.example.com",22)
If (success <> 1) Then
Debug.Print sftp.LastErrorText
Exit Sub
End If
' Authenticate using both a password and private key.
success = sftp.AuthenticatePwPk("myLogin","myPassword",key)
If (success = 1) Then
Debug.Print "Authentication is successful!"
Exit Sub
End If
' If we get here, it means the authentication failed.
' To find out why, get the LastJsonData
Dim json As ChilkatJsonObject
Set json = sftp.LastJsonData()
json.EmitCompact = 0
' This is the JSON if the key is correct, but the password is incorrect:
' {
' "public_key_type": "rsa",
' "partialAuthResult": "publickey success. continue to authenticate with password...",
' "authResult": "failed",
' "authFailReason": "Password is incorrect"
' }
' This is the JSON if the key is incorrect. We won't know if the password is also incorrect until
' the key is made correct so that authentication proceeds to check the password.
' {
' "public_key_type": "rsa",
' "authResult": "failed",
' "authFailReason": "Key is incorrect"
' }
' To get the authResult anbd authFailReason:
Debug.Print "authResult: " & json.StringOf("authResult")
Debug.Print "authFailReason: " & json.StringOf("authFailReason")
End Sub
|