DataFlex
DataFlex
Get the SSH Server's Authentication Methods
See more SSH Examples
Demonstrates the Chilkat Ssh.GetAuthMethods method, which queries a connected but unauthenticated SSH server for the authentication methods it advertises. It takes no arguments and returns a lowercase, comma-separated list such as publickey,password,keyboard-interactive. Call it after Connect and before authenticating.
Background: Knowing what the server accepts lets a client choose the right authentication path — for example, falling back to keyboard-interactive when password auth is not offered. Note the documented connection side effect: querying methods advances the SSH authentication state, so call it at the correct point in the sequence.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iSshPort
String sMethods
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the Ssh.GetAuthMethods method, which queries a connected but unauthenticated SSH
// server for the authentication methods it advertises. It takes no arguments and returns a
// lowercase, comma-separated list such as "publickey,password,keyboard-interactive".
Get Create (RefClass(cComChilkatSsh)) To hoSsh
If (Not(IsComObjectCreated(hoSsh))) Begin
Send CreateComObject of hoSsh
End
// Connect to the SSH server. Port 22 is the usual SSH port.
Move 22 To iSshPort
Get ComConnect Of hoSsh "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Query the advertised authentication methods. Call after Connect, before authenticating.
Get ComGetAuthMethods Of hoSsh To sMethods
Get ComLastMethodSuccess Of hoSsh To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Server auth methods: " sMethods
Send ComDisconnect To hoSsh
End_Procedure