EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Blocking SSH call?

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.
#1070
Posted: 08/24/2006 11:49:18
by Jeff Lindborg (Basic support level)
Joined: 06/12/2006
Posts: 26

I'm sure I'm being slow here but I'm just looking for a very basic way to do a blocking SSH call - I need to call a remote compiler that can take quite a while to finish and then go fetch the results from a file. The SSH examples using the ElSimpleSSHClientX control are built around issuing commands and getting text output back. I'm looking only to call a specific app with different command line apps and I want execution to wait until it's completed. The Command interface seems to be what I want here but I can't figure out how to use it properly here and the docs are a little light on examples.
Is there an easy way to do this I'm missing?
thanks
-Jeff
#1074
Posted: 08/24/2006 14:35:41
by Eugene Mayevski (EldoS Corp.)

Do you mean that you need to issue a sequence of Command's? Then you can use Commands property. But frankly speaking I don't understand what exactly you want to do. Run a compiler - how? "gcc mycode >some_output_file" or using the script file? Get the results from file - how? Download the file via SFTP or ... ?


Sincerely yours
Eugene Mayevski
#1077
Posted: 08/24/2006 15:34:35
by Jeff Lindborg (Basic support level)
Joined: 06/12/2006
Posts: 26

Sorry - probably offered too much information there. All I want to do is issue a single command on the remote box and wait until it's complete. That's it. I need my application to block until the command completes. The output of the command and all other details are not important.

So, for example, If I wanted to issue "ls -R > test.txt" from root, it will take a while to complete. How would I issue that call such that my app can block until the ls command returns?
#1078
Posted: 08/24/2006 16:05:11
by Eugene Mayevski (EldoS Corp.)

TElSimpleSSHClient is always blocking, so you don't need anything special


Sincerely yours
Eugene Mayevski
#1079
Posted: 08/24/2006 16:23:47
by Jeff Lindborg (Basic support level)
Joined: 06/12/2006
Posts: 26

Well, as noted I may be slow but your examples don't make it obvious on how I actually leverage this and the help has almost no usable details for me. In your sample app (which I'm testing with) the TeISimpleSSHClientX object has it's "sendtext" interface called when you press the send button. Fine. However it returns right away even though the remote command has not completed. It then goes into a message loop and you wait for text to get spit back which can come in multiple chunks and it gets copied out into the memo1 text control.

Other than writing my own routine to sit there and watch the output until something like a command prompt comes back (i.e. being smart enough to ignore all the console output flying by), there doesn't seem to be a nifty way to issue a "run this command on the remote server and return control to me when it completes on the server".

I'm sure what you mean by "it's always blocking" is that it blocks until the command is sent, not until it's complete. Unless I'm missing something really obvious here.
#1080
Posted: 08/24/2006 16:35:41
by Eugene Mayevski (EldoS Corp.)

when you use Command property, command channel is used. This is different from what you see now. Please just try modifying the sample to use this property and you will see everything yourself


Sincerely yours
Eugene Mayevski
#1081
Posted: 08/24/2006 16:50:53
by Jeff Lindborg (Basic support level)
Joined: 06/12/2006
Posts: 26

sigh... you do realize how maddening this thread is, right? Go back to my first post - what did I ask? How can I use the command property. I can find NO examples of how this is done and trying to test with it is proving fruitless.

Never mind - clearly I'll just have to bang heads with this till I figure it out on my own.
#1085
Posted: 08/25/2006 00:57:41
by Eugene Mayevski (EldoS Corp.)

The use is simple --

Client.Command = "ls -R > test.txt";

That's all you need to add.


Sincerely yours
Eugene Mayevski
#1087
Posted: 08/25/2006 01:55:26
by Eugene Mayevski (EldoS Corp.)

Regarding "blocking" - after the successful call to Open the command is already sent and you can receive the reply data. Do the reading until there's no more data and the connection is closed. I have added the sample request to our ToDo list.


Sincerely yours
Eugene Mayevski
#1112
Posted: 08/30/2006 13:53:59
by Jeff Lindborg (Basic support level)
Joined: 06/12/2006
Posts: 26

yeah, I get how to call it. What I don't get is how to tell when it's done. I have come to the conclusion that this just doesn't work the way you think it does and I await your example using ActiveX.

When you set the command string and then open it, the command does, indeed, get executed. There is no reply data to capture, however. I put breakpoints in every function defined off the object and OnRecieve never fires. MessageLoop, OnAuthenticateSuccess and OnKeyValidate all are fired but nothing ever tickles onreceive.

And, of course, the Open command returns long before the command finishes executing on the server in the case of a call to something that takes a while. I can put dumb sleeps in there and wait for the file to show up and it does eventually complete but there seems to be no good way to block and your suggestion does not work.

I figured the "commands" property (plural) might work but that does not appear to be implemented in ActiveX so no go there.

I also tried forcing a ReceiveText or a ReceiveData call after the open command but this did no better.

So... I'm back to opening a shell and parsing output to manually tell when the command prompt comes up and then raising an event that tells the calling routine that the command it issued has completed. More than a little awkward but I see no other choice here.

When you have a sample done in ActiveX that implements a proper blocking call by any means, let me know - unless I'm missing something big there isn't a cleaner way to do this with the current implementation.
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

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