EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSHClient.OnSendCommandRequest not firing

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#13595
Posted: 06/07/2010 02:28:18
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

Hi,
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
Quote
echo foo

Whereas I would expect it to be
Quote
echo foo
echo bar


Could you please explain what I'm doing wrong?

Code
         private static TElSimpleSSHClient client = new TElSimpleSSHClient();        

        static void Main(string[] args)
        {
            SBUtils.Unit.SetLicenseKey("key");
            TElSSHMemoryKeyStorage mks = new TElSSHMemoryKeyStorage();
            client.KeyStorage = mks;

            client.Username = "user";
            client.Password = "password";
            client.Address = "10.0.0.113";
            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");

            client.Open();

            Console.ReadLine();
        }

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


        static void client_OnSendCommandRequest(object Sender, string Command, int CommandIdx)
        {
            Console.WriteLine(Command);
        }

        static void client_OnKeyValidate(object Sender, TElSSHKey ServerKey, ref bool Validate)
        {
            Validate = true;
        }
#13597
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
#13609
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 8.0.176.21194, which I believe is the latest.

Cheers.
#13610
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
#13611
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
Code
            client.Commands.Add("echo foo > foo.txt");
            client.Commands.Add("echo bar > bar.txt");


Only foo.txt is created.
#13614
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)?
#13625
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").
#13626
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?
#13627
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.
#13636
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:
Code
ClientDisconnected = false;
do
{
  st = client.ReceiveText();
  if (st.Length > 0)
    Console.WriteLine(st);
} while (!ClientDisconnected);

(you need to set ClientDisconnected to true in OnCloseConnection event handler)
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 3131 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!