Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Create a new SSH connection and send a few commands (HELP ME PLEASE!!!)

$
0
0
Hello,
I need help to create a connection in SSH and send a few commands (for a Linux SO).
After send those commands i need this connection alive for a while:

My code example:


namespace test
{
public partial class Main : Form
{
    string Host = 192.168.1.1;
    string Username = "root";
    string Password = "root";

try{

                PasswordAuthenticationMethod authMethod = new PasswordAuthenticationMethod(Username, Password);
                ConnectionInfo connectionInfo = new ConnectionInfo(Host, Username, authMethod);

                using (var ssh = new SshClient(connectionInfo))
                {

                   ssh.Connect();

                   var cmd = ssh.CreateCommand(string.Format("cd /;gzip -d serial_testmode_2016-04-21_16.tar.gz;tar -xvf serial_testmode_2016-04-21_16.tar")).Execute();

                    ssh.Disconnect();

                    ssh.Connect();


                   var cmd = ssh.CreateCommand(string.Format("cd root/serial_testmode")).Execute();


                    // Before that i need send other commands to serial communication... But i need the  SSH connection alive too!

              if(serialPort.IsOpen)
                {
                     try
                       {
                          serialPORT.Write(Comand.LedsOn);

                   //... and goes on....
                       }
                }
        ssh.Disconnect();
        }
    }
}
}

The problem are, they send a the first command in ssh and frozen... why?
Thanks for any help!

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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