Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
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 Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ssh;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ssh: TSsh;
sshPort: Integer;
methods: string;
begin
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 := TSsh.Create;
// Connect to the SSH server. Port 22 is the usual SSH port.
sshPort := 22;
success := ssh.Connect('ssh.example.com',sshPort);
if (success = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
// Query the advertised authentication methods. Call after Connect, before authenticating.
methods := ssh.GetAuthMethods();
if (ssh.LastMethodSuccess = False) then
begin
WriteLn(ssh.LastErrorText);
Exit;
end;
WriteLn('Server auth methods: ' + methods);
ssh.Disconnect();
ssh.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.