If we execute the following function (see below) in cycle, shell.ExecuteCommand hangs around 5th-20th iteration.
SSH server: sshd version OpenSSH_6.9, OpenSSL 1.0.2d
Ciphers used aes128-ctr, Kex algorithm diffie-hellman-group14-sha1
Another question - are these components thread safe?
TScSSHClient;
TScFileStorage;
TScSSHShell;
Code: Select all
function TForm1.SSHexec(host,user,psw,command: string; id: integer): string;
var
ssh: TScSSHClient;
storage: TScFileStorage;
shell: TScSSHShell;
list: TStrings;
i: Integer;
begin
ssh:=TScSSHClient.Create(self);
storage:=TScFileStorage.Create(self);
shell:=TScSSHShell.Create(self);
list:=TStringList.Create;
Try
ssh.HostName:=host;
ssh.User:=user;
ssh.Password:=psw;
ssh.Timeout := 3;
ssh.KeyStorage:=storage;
ssh.OnServerKeyValidate:=sshServerKeyValidate;
ssh.Connect;
shell.Client:=ssh;
shell.Environment.Text:='PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user1/.local/bin:/home/user1/bin';
shell.Connect;
list.Text:=command;
Result:=IntToStr(id)+'. ';
for i:=0 to list.Count-1 do
begin
if Result<>'' then Result:=Result+#13#10;
Result:=Result+shell.ExecuteCommand(list[i]+#13#10);
end;
shell.Disconnect;
ssh.Disconnect;
except
on e:Exception do Result:='Error: '+e.Message;
end;
ssh.Free;
storage.Free;
shell.Free;
list.Free;
end;
procedure TForm1.sshServerKeyValidate(Sender: TObject; NewServerKey: TScKey; var Accept: Boolean);
begin
Accept:=True;
end;