This project is read-only.

Interacting with and also capturing an SSH session

Sep 11, 2015 at 5:14 PM
Edited Sep 11, 2015 at 5:24 PM
This is a conceptual question. I just need to know where to get started.

My application is to connect via SSH to an embedded device and then send a series of commands, parsing the results and sending other commands based on the parsed results.

I can do this already using SshClient and the ShellStream classes.

The problem now is that I would ALSO like to be able to capture ALL the traffic on my ShellStream. In other words, I would like to somehow log everything I am sending/receiving through the ShellStream.

The "hard" way to do this is to explicitly log everything I send and receive by inserting logging calls into all the places where I invoke Send() and Expect(), for example. Unfortunately, this means I need to worry about situations where I use Expect() to capture a particular string in the response to the command I send, but I want to log all the text I get back, not only what is captured by the regex which I give to Expect.

Is there an easy way for me to leave all my command-response interactions untouched but also log everything that comes through the ShellStream?
Oct 28, 2015 at 1:48 PM
There is an easy way to do this.

The ShellStream class has an event available called "DataReceived"

By registering to this event, one can get all data received by the shell stream regardless of whatever the Expect methods are doing.

The use case for doing this is to be able to send commands and parse results AND also capture everything coming from the ShellStream (eg for logging, etc).