Using SSH.NET to connect to Remote Hosts
<p>I'm trying to automate configuring remote hosts, we have hundreds of these devices, we normally do it through USB programming, but if I could get a script to connect to these devices and do it programmatically, it would free up time. </p>

<p>These devices run some type of linux os, i'm not sure exactly, but they do have SSH enabled and confirm server host keys when you first connect to them via utility like PuTTY.</p>

<p>For now, i'm just trying to initiate an SSH session with the device. I've done quite a bit of research, and have come up with this:</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Renci.SshNet;
using Renci.SshNet.Common;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Connection information
            string user = "admin";
            string pass = "********";
            string host = "IP Address";

            //Set up the SSH connection
            using (var client = new SshClient(host, user, pass))
            {

                //Accept Host key
                client.HostKeyReceived += delegate (object sender, HostKeyEventArgs e)
                {
                    e.CanTrust = true;
                };

                //Start the connection
                client.Connect();

                var output = client.RunCommand("show device details");


                client.Disconnect();
                Console.WriteLine(output.ToString());
                Console.ReadLine();
            }
        }
    }
}
</code></pre>

<p>The problem is this doesn't seem to execute the command listed. The console window comes up, and I can access the same device by WebGUI and see the log file, it shows a connection being made, but when I break the execution and see the variable values the output variable shows null. </p>

<p>If I let the execution sit, with the console window open (just shows a blinking cursor in the upper left), the connection times out after 10 minutes and connection is lost, which I also see happen in the device log.</p>

<p>Why would does this not seem to execute the runcommand and store the results in the output variable?</p>