Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSsh
LOCAL lcAuthMethods

lnSuccess = 0

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

loSsh = CreateObject('Chilkat.Ssh')

* To get the authentication methods offered by an SSH server, we first connect.
lnSuccess = loSsh.Connect("example.com",22)
IF (lnSuccess <> 1) THEN
    ? loSsh.LastErrorText
    RELEASE loSsh
    CANCEL
ENDIF

* Next, we call GetAuthMethods to receive a comma separated list of authentication methods
lcAuthMethods = loSsh.GetAuthMethods()
IF (loSsh.LastMethodSuccess <> 1) THEN
    ? loSsh.LastErrorText
    RELEASE loSsh
    CANCEL
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..
lnSuccess = loSsh.Connect("example.com",22)
IF (lnSuccess <> 1) THEN
    ? loSsh.LastErrorText
    RELEASE loSsh
    CANCEL
ENDIF

lnSuccess = loSsh.AuthenticatePw("myLogin","myPassword")
IF (lnSuccess <> 1) THEN
    ? loSsh.LastErrorText
    RELEASE loSsh
    CANCEL
ENDIF

? "SSH Authentication successful."

* ...

loSsh.Disconnect()

RELEASE loSsh