ShellStream works - Sheel and Command do not work

Jan 14, 2014 at 4:34 PM
Edited Jan 14, 2014 at 4:40 PM
Hi all,

I have to connect to a Linux machine which has an SSH server running on it. Connecting using ShellStream works fine:
ConnectionInfo connectionInfo = new PrivateKeyConnectionInfo ( "10.148.12.190", 22, "user", new PrivateKeyFile ( "id_rsa" ) );
SshClient sshClient = new SshClient ( connectionInfo );
sshClient.Connect ();

//////////////////////////////
ShellStream stream = sshClient.CreateShellStream ( "xterm", 80, 50, 1024, 1024, 1024 );
StreamReader reader = new StreamReader ( stream );
StreamWriter writer = new StreamWriter ( stream );
writer.AutoFlush = true;
string result = reader.ReadToEnd ();
Console.WriteLine ( result );
writer.WriteLine ( "TOPCELL" );
result = reader.ReadToEnd ();
Console.WriteLine ( result );
//////////////////////////////

sshClient.Disconnect ();
So far, so good!

But my original intention was to use SshCommand (because I need asynchronous execution). I used SshCommand in other projects before and never had any problems. But for some reason the SSH server does not see any byte of the command when I use this code:
ConnectionInfo connectionInfo = new PrivateKeyConnectionInfo ( "10.148.12.190", 22, "user", new PrivateKeyFile ( "id_rsa" ) );
SshClient sshClient = new SshClient ( connectionInfo );
sshClient.Connect ();

//////////////////////////////
SshCommand sshCommand = sshClient.CreateCommand ( "TOPCELL" );
string result = sshCommand.Execute ();
Console.WriteLine ( result );
//////////////////////////////

sshClient.Disconnect ();
When I debug this code sshCommand.Execute() never returns.

The developer of the Linux SSH server does not have any clue because sending the command via ShellStream and via putty works fine. Only Shell and SshCommand seem to have problems.

Any ideas what I could try to fix the problem?

I should mention that the SSH server sends some welcome string before I send the command. Is it possible that this confuses the SshClient somehow?

Thanks,
Oliver