EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSHClient.OnSendCommandRequest not firing

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
Posted: 06/07/2010 02:28:18
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

I'm using the SecureBlackBox SimpleSSHClient in .NET and am having trouble getting the OnSendCommandRequest event to fire when I expect it to.

As I understand it, the even should fire before every command in Commands is executed. However, it seems that it only fires for the first command.

I can replicate this with the example program below. The output from the program is
echo foo

Whereas I would expect it to be
echo foo
echo bar

Could you please explain what I'm doing wrong?

         private static TElSimpleSSHClient client = new TElSimpleSSHClient();        

        static void Main(string[] args)
            TElSSHMemoryKeyStorage mks = new TElSSHMemoryKeyStorage();
            client.KeyStorage = mks;

            client.Username = "user";
            client.Password = "password";
            client.Address = "";
            client.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_PASSWORD;
            client.RequestTerminal = true;

            client.OnKeyValidate += new SBSSHCommon.TSSHKeyValidateEvent(client_OnKeyValidate);
            client.OnSendCommandRequest += new SBSSHCommon.TSSHCommandExecutionEvent(client_OnSendCommandRequest);
            client.OnError += new SBSSHCommon.TSSHErrorEvent(client_OnError);

            client.Commands.Add("echo foo");
            client.Commands.Add("echo bar");



        static void client_OnError(object Sender, int ErrorCode)
            Console.WriteLine("Error: " + ErrorCode);

        static void client_OnSendCommandRequest(object Sender, string Command, int CommandIdx)

        static void client_OnKeyValidate(object Sender, TElSSHKey ServerKey, ref bool Validate)
            Validate = true;
Posted: 06/07/2010 04:04:58
by Eugene Mayevski (EldoS Corp.)

The code is correct, and the event should be fired for each command - DoCommandRequest method (which calls the event handler) is called right before SSH2SendCommand... method, which sends the command.

Is "echo bar" command actually executed?

Sincerely yours
Eugene Mayevski
Posted: 06/07/2010 18:50:51
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

I've put a breakpoint in client_OnSentCommandRequest: it is only triggered for "echo foo".

I'm using version, which I believe is the latest.

Posted: 06/08/2010 00:22:36
by Eugene Mayevski (EldoS Corp.)

I understood that it got fired once. But what commands are actually *executed* on the server?

Sincerely yours
Eugene Mayevski
Posted: 06/08/2010 00:30:31
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

Oh, ok. To quickly test I changed it to
            client.Commands.Add("echo foo > foo.txt");
            client.Commands.Add("echo bar > bar.txt");

Only foo.txt is created.
Posted: 06/08/2010 04:51:18
by Ken Ivanov (EldoS Corp.)

It seems that the server does not close the command channel after the first command finishes execution. Could you please specify the value of the ServerSoftwareName property (please check it after the connection has been negotiated)?
Posted: 06/08/2010 22:48:27
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

ServerSoftwareName is "OpenSSH_5.2".

I've also been able to replicate the problem with freeSSHd (ServerSoftwareName "WeOnlyDo 2.1.3").
Posted: 06/08/2010 23:00:49
by Ken Ivanov (EldoS Corp.)

Hmm, at least OpenSSH should work flawlessly.

I have just noticed a suspicious line in your code. Could you please try to set RequestTerminal to false and check if it changes something?
Posted: 06/08/2010 23:46:34
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

Setting RequestTerminal to false does not change the behaviour.
Posted: 06/09/2010 16:39:53
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi. In order to make it work you need to interact with SimpleSSH client, i.e. receive data through it, or something else. Open() method just initializes SSH connection, and sends first command.
For example, this code will send all needed commands:
ClientDisconnected = false;
  st = client.ReceiveText();
  if (st.Length > 0)
} while (!ClientDisconnected);

(you need to set ClientDisconnected to true in OnCloseConnection event handler)
Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.



Topic viewed 3101 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!