Quantcast
Channel: SSH.NET Library
Viewing all articles
Browse latest Browse all 2955

New Post: How to maintain a 'conversation' with an SSH session?

$
0
0
I know this sounds weird. In the examples I can find, a send command & get results type of session is just that: Connect, create SshShell, WriteLine, ReadLine, done.

But this isn't what a real session is like when you need to drill down the command tree, then gather the results of just the last/current command you issued. You can't drill down a few levels in, say, a Cisco router with, for example, enable, enablePass, conf t, int 123, etc. by disconnecting and reconnecting for every command.

And I'm noticing that using Expect(), which is an amazing and extremely useful function, does NOT show you just the output of the latest command. The string returned can be from a few commands back, as if it's stuck in some buffer and can't get out.

So what is the proper way to issue several commands in a single session, taking in the result (as a string) of each command?

I showed you a simple test case for this in my email about too many line feeds (ODOA, or CRLF). This was fixed by altering the source, creating a SshShell.WriteLine2() function that gave \n\r at the end of the line, and modifying SshShell.WriteLine() to only output \r:
        public void WriteLine2(string line)
        {
            var commandText = string.Format("{0}{1}", line, "\r\n");
            
            this.Write(commandText);
        }
        public void WriteLine(string line)
        {
            var commandText = string.Format("{0}{1}", line, "\r");

            this.Write(commandText);
        }
I could have come up with a more intuitive name, but I figure this is a temporary patch/fix. Ideally, this would be chosen by a boolean class level attribute.

I've been trying to concisely log into a Cisco router in enable mode for over a week now. Oddly, SshShell.Flush() seems to have no impact at all on the readstream/buffer.

Viewing all articles
Browse latest Browse all 2955

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>