program TestSSHClient;
{Test program for telnetsshclient
Written by Reinier Olislagers 2011.
Modified for libssh2 by Alexey Suhinin 2012.
License of code:
* MIT
* LGPLv2 or later (with FreePascal static linking exception)
* GPLv2 or later
according to your choice.
Free use allowed but please don't sue or blame me.
Uses other libraries/components; different licenses may apply that also can influence the combined/compiled work.
Run: sshtest <serverIPorhostname> [PrivateKeyFile]
}
{$mode objfpc}{$H+}
{$APPTYPE CONSOLE}
uses
telnetsshclient;
var
comm: TTelnetSSHClient;
Command: string;
begin
writeln('Starting.');
comm:=TTelnetSSHClient.Create;
comm.HostName:= 'suselinux02'; // ParamStr(1); //First argument on command line
if comm.HostName='' then
begin
writeln('Please specify hostname on command line.');
halt(1);
end;
//comm.PrivateKeyFile := 'C:\freepascal\projects\SSH-Test2\id_rsa';
comm.PrivateKeyFile := 'id_rsa';
comm.TargetPort:=''; //auto determine based on protocoltype
comm.UserName:='d197'; //change to your situation
comm.Password:=''; //change to your situation
comm.ProtocolType:=SSH; //Telnet or SSH
//comm.Sock.SSL.Ciphers := 'chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com';
writeln(comm.Connect); //Show result of connection
if comm.Connected then
begin
writeln('Server: ' + comm.HostName + ':'+comm.TargetPort+', user: '+comm.UserName);
writeln('Welcome message:');
writeln(comm.WelcomeMessage);
Command:='ls -al';
writeln('*** Sending ' + Command);
writeln('*** Begin result****');
writeln(comm.CommandResult(Command));
writeln('*** End result****');
writeln('');
writeln('');
Command:='df -h';
writeln('*** Sending ' + Command);
writeln('*** Begin result****');
writeln(comm.CommandResult(Command));
writeln('*** End result****');
writeln('');
writeln('');
writeln('All output:');
writeln('*** Begin result****');
writeln(comm.AllOutput);
writeln('*** End result****');
comm.Disconnect;
end
else
begin
writeln('Connection to ' +
comm.HostName + ':' +
comm.TargetPort + ' failed.');
end;
comm.Free;
end.