Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkSshW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSshW ssh;
    int sshPort;
    const wchar_t *methods;

    success = FALSE;

    //  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".

    ssh = CkSshW_Create();

    //  Connect to the SSH server.  Port 22 is the usual SSH port.
    sshPort = 22;
    success = CkSshW_Connect(ssh,L"ssh.example.com",sshPort);
    if (success == FALSE) {
        wprintf(L"%s\n",CkSshW_lastErrorText(ssh));
        CkSshW_Dispose(ssh);
        return;
    }

    //  Query the advertised authentication methods.  Call after Connect, before authenticating.
    methods = CkSshW_getAuthMethods(ssh);
    if (CkSshW_getLastMethodSuccess(ssh) == FALSE) {
        wprintf(L"%s\n",CkSshW_lastErrorText(ssh));
        CkSshW_Dispose(ssh);
        return;
    }

    wprintf(L"Server auth methods: %s\n",methods);

    CkSshW_Disconnect(ssh);


    CkSshW_Dispose(ssh);

    }