Blocking SSH to some clients hang
Posted: Tue 14 Apr 2020 02:17
Hi, using latest SecureBridge, purchased last week, Delphi XE4.
It seems I can only get Blocking (NonBlocking=False) mode to 'proper' Linux distros. CentOS & Debian servers work 100%, but our app access hundreds of various brand routers, that all support SSH. However, ANY of the routers hang when I send ExecuteCommand, all devices are Linux based so I'm not sure where I should start to look to find the problem.
Below is (not) my code but illustate the issue. I try to connect to 4 different devices, a server and 3 different types of routers; Mikrotik; Ubiquity; Cambium, all on latest software/firmware.
In NonBlocking=False, servers work 100% but routers just hang when I send the ExecuteCommand.
NonBlocking=True (sshshell.WriteString; sshclient.AsyncReceive+ReadString) the routers also send/reply correctly, but I'd really like to get NonBlocking=False working for all devices.
It is impossible for me to know when a reply is finished, as we sometimes work with unknown hardware, many times with customers that have old, slow routers on unreliable connections that sometimes drop regularly.
I then try to use it like this:
PS: Eventually this code will have to run in it's own thread. Also I need to work with many routers simultaneously, and as fast as possible; I cannot afford a lot of sleeps+wait-loops, any advice welcome as I'd prefer not to redesign the app workflow.
Greetings
AntonE
Locking down in South Africa
It seems I can only get Blocking (NonBlocking=False) mode to 'proper' Linux distros. CentOS & Debian servers work 100%, but our app access hundreds of various brand routers, that all support SSH. However, ANY of the routers hang when I send ExecuteCommand, all devices are Linux based so I'm not sure where I should start to look to find the problem.
Below is (not) my code but illustate the issue. I try to connect to 4 different devices, a server and 3 different types of routers; Mikrotik; Ubiquity; Cambium, all on latest software/firmware.
In NonBlocking=False, servers work 100% but routers just hang when I send the ExecuteCommand.
NonBlocking=True (sshshell.WriteString; sshclient.AsyncReceive+ReadString) the routers also send/reply correctly, but I'd really like to get NonBlocking=False working for all devices.
It is impossible for me to know when a reply is finished, as we sometimes work with unknown hardware, many times with customers that have old, slow routers on unreliable connections that sometimes drop regularly.
Code: Select all
function TForm2.TestSSH(const aIP,aUN,aPW,aCMD:String):String;
var ScSSHClient : TScSSHClient;
ScSSHShell : TScSSHShell;
ScFileStorage: TScFileStorage;
ScSSHChannel:TScSSHChannel;
begin
ScFileStorage:= TScFileStorage.Create(nil);
ScSSHClient := TScSSHClient .Create(nil);
ScSSHShell := TScSSHShell .Create(nil);
ScSSHClient .KeyStorage:=ScFileStorage;
ScSSHShell .Client :=ScSSHClient;
ScSSHClient .HostName :=aIP;
ScSSHClient .User :=aUN;
ScSSHClient .Password :=aPW;
ScSSHClient .Port :=22;
ScSSHClient .HostKeyAlgorithms.AsString :='ssh-rsa,ssh-dss,ecdsa';
ScSSHClient .OnServerKeyValidate:=ScSSHClient1ServerKeyValidate;
ScSSHShell .NonBlocking :=False;
// ScSSHShell .OnAsyncReceive :=ScSSHShell1AsyncReceive;
try
ScSSHClient .Connect;
ScSSHShell .Connect;
except
on E: Exception do begin
ScSSHShell.Free;
ScSSHClient.Free;
ScFileStorage.Free;
exit('ERROR:'+E.Message);
Exit;
end;
end;
Result:=ScSSHShell.ExecuteCommand(aCMD);
//HANGS ON ABOVE LINE, NEVER REACH HERE FOR ROUTERS, SERVERS ARE INSTANT AND 100% CORRECT REPLY
ScSSHShell.Disconnect;
ScSSHClient.Disconnect;
ScSSHShell.Free;
ScSSHClient.Free;
ScFileStorage.Free;
end;
Code: Select all
Memo1.Lines.Add(TestSSH('10.1.1.10' ,'root' ,'passw')' ,'cat /etc/resolv.conf')); //CentOS 7 works 100%
Memo1.Lines.Add(TestSSH('192.168.0.1','admin','passw','/system resource print')); //Mikrotik router, HANGS
Memo1.Lines.Add(TestSSH('10.1.49.253','admin','passw','cat /proc/cpuinfo') //Ubiquity router HANGS
Memo1.Lines.Add(TestSSH('10.1.73.254','admin','passw','show dashboard')); //Cambium router HANGS
Greetings
AntonE
Locking down in South Africa