Sample code for 30+ languages & platforms
Lianja

Get SSH Server Authentication Methods

See more SSH Examples

Demonstrates how to get the authentication methods of an SSH server.

This example requires Chilkat v9.5.0.78 or greater.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loSsh = createobject("CkSsh")

// To get the authentication methods offered by an SSH server, we first connect.
llSuccess = loSsh.Connect("example.com",22)
if (llSuccess <> .T.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

// Next, we call GetAuthMethods to receive a comma separated list of authentication methods
lcAuthMethods = loSsh.GetAuthMethods()
if (loSsh.LastMethodSuccess <> .T.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

// For example: publickey,password,keyboard-interactive
? "Authentication methods suported by this serve: " + lcAuthMethods

// IMPORTANT:
// Getting the authentication methods will intentionally disconnect from the server.
// We'll need to re-connect, etc. to continue..

// For example..
llSuccess = loSsh.Connect("example.com",22)
if (llSuccess <> .T.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

llSuccess = loSsh.AuthenticatePw("myLogin","myPassword")
if (llSuccess <> .T.) then
    ? loSsh.LastErrorText
    release loSsh
    return
endif

? "SSH Authentication successful."

// ...

loSsh.Disconnect()


release loSsh