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

New Post: SSH command using the RunCommand() doesn't work?

$
0
0
Hi,

There are two ways to do this
  1. ShellStream and Async write/read (quite difficult)
  2. Use PortForwarding
    In your case you want the ssh port (22) of the machine 192.168.1.11
(untested pseudo code)
         using (var client = new SshClient("192.168.1.10", "root", "magic!0n3"))
            {
                client.Connect();

                // foward remote ssh port to your local machine
                ForwardedPortLocal forwarding =  new ForwardedPortLocal("127.0.0.1", "12345", "192.168.1.11", "22");
                client.AddForwardedPort(forwarding);
                forwarding.Start();

                // connect to it
                SshClient forwardedSsh = new SshClient("127.0.0.1", 12345, "root", "password/key");
                forwardedSsh.Connect();

                // run your commands
                MessageBox.Show(forwardedSsh.RunCommand("ls").Result);
            }
RunCommand() is for short and non-interactive commands.
Another Ssh is a long and interactive command.

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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