EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSHClient.OnSendCommandRequest not firing

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
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 (Team)

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 (Team)

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 (Team)

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 (Team)

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: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.



Topic viewed 3329 times

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


Back to top

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

Got it!