Problem with remote host - WeOnlyDo Discussion board

Problem with remote host (wodSSH / wodSSH.NET)

by Helmut Schnur, Friday, July 22, 2005, 08:49 (7064 days ago)

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

by wodSupport, Friday, July 22, 2005, 10:15 (7064 days ago) @ Helmut Schnur

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...