Problem with remote host (wodSSH / wodSSH.NET)
I have a strange problem with a remote host closing connection sometimes. I'm using the following code:
try
{
SSH ssh = new SSH();
ssh.Hostname = hostname ;
ssh.Login = user ;
ssh.Password = password ;
ssh.TerminalType = tty ;
ssh.Blocking = true;
ssh.Timeout = 0;
ssh.Command = ls -la;echo XXX
;
ssh.Connect();
string data = ssh.WaitFor( XXX );
Trace(data);
}
catch (Exception exc)
{
Trace(exc.Message);
}
Doing this sometimes it works, sometimes I immediately get the exception Remote host has closed the connection . What I'm doing wrong?
Kind regards,
Helmut
Re: Problem with remote host
Helmut,
it's because you set Command property. When set, it is executed instead of shell, so as soon as that command completes, connection is closed from remote side.
Basically, you have here race condition - what will happen first, will command finish first, or your WaitFor? Obviously, sometimes one wins, sometimes another...