Just started evaluating your secure bridge libraries. Please note i am a novice :) I am probably doing something wrong. Hopefully you can help me spot the error. I made a first attempt in creating a ssh client by gathering some example code from this forum. The SSH connection should execute a remote linux command and provide me the output back.
Some technical details:
Trying this on openSUSE Leap 15 with Free Pascal Compiler version 3.0.4 [2018/05/13] for x86_64. SSH attempts were made to openSUSE and Ubuntu VM, but both fail.
Attempt output openSUSE:
Exception at 0000000000548384: Exception:
You are using SecureBridge Trial edition!
You may register SecureBridge at http://www.devart.com.
SSH client connected!
CMD shell connected!
.... Note: From here takes some time (~10 seconds), waiting on timeout i guess but then follows another exception ...
An unhandled exception occurred at $0000000000424C8A:
EInOutError: Invalid file handle
$0000000000424C8A
On openSUSE vmware machine in journal log:
Apr 14 15:41:27 cereb-dev sshd[15686]: error: ioctl(TIOCSCTTY): Input/output error
Apr 14 15:41:27 cereb-dev sshd[15686]: error: /dev/pts/2: No such file or directory
Apr 14 15:41:27 cereb-dev sshd[15686]: error: open /dev/tty failed - could not set controlling tty: No such device or address
On Ubuntu similar error.
The source code i use.
Code: Select all
program ssh_test;
uses {$ifdef unix} cthreads, cmem, {$endif}
SysUtils,
Classes,
ScSSHUtils,
ScTypes,
ScUtils,
ScBridge,
ScSSHChannel,
ScSSHClient;
type
TMyClass = class
class procedure ScSSHClientServerKeyValidate(Sender: TObject;
NewServerKey: TScKey; var Accept: Boolean);
end;
var
searchResult: TSearchRec;
ScSSHClient: TScSSHClient;
ScFileStorage: TScFileStorage;
ScSSHChannel : TScSSHChannel;
CMDshell : TScSSHShell;
class procedure TMyClass.ScSSHClientServerKeyValidate(Sender: TObject;
NewServerKey: TScKey; var Accept: Boolean);
var
Key: TScKey;
fp, msg: string;
begin
Key := ScFileStorage.Keys.FindKey(ScSSHClient.HostName);
if (Key = nil) or not Key.Ready then begin
NewServerKey.GetFingerPrint(haMD5, fp);
Key := TScKey.Create(nil);
try
Key.Assign(NewServerKey);
Key.KeyName := ScSSHClient.HostName;
ScFileStorage.Keys.Add(Key);
except
Key.Free;
raise;
end;
Accept := True;
end;
end;
begin
try
ScFileStorage := TScFileStorage.Create(nil);
ScSSHClient := TScSSHClient.Create(nil);
CMDShell := TScSSHShell.Create(nil);
ScSSHClient.KeyStorage := ScFileStorage;
ScSSHClient.HostName := '<ip address or name>';
ScSSHClient.User := '<username>';
ScSSHClient.Password := '<password>';
ScSSHClient.OnServerKeyValidate := TMyClass.ScSSHClientServerKeyValidate;
ScSSHClient.Connect;
if (ScSSHClient.connected) then begin
writeln('SSH client connected!');
end
else begin
writeln('SSH client failed!');
end;
CMDShell.Client := ScSSHClient;
CMDShell.Connect;
if (CMDShell.Connected) then begin
writeln('CMD shell connected!');
end
else begin
writeln('CMD shell failed!');
end;
CMDShell.ExecuteCommand('uname -a');
except
on E: Exception do
writeln(E.ClassName, ': ', E.Message);
end;
ScSSHClient.DisConnect;
ScSSHClient.Destroy;
ScSSHClient.Free;
end.