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

New Post: How to send results of client.RunCommand to a listbox WinForms C#

$
0
0
Hi There

I am trying to use SSH.Net in a WinForms app, however I am having issues trying to ouput the result of a command to a listbox. I can connect fine to the server.
Debugging the line with string output I get "output = "Renci.SshNet.SshCommand" The value of command is correct with ls -la
private void btnExecute_Click(object sender, EventArgs e)
        {
            var connectionInfo = new PasswordConnectionInfo(host, port, username, password);
            lblStatus.Text = "Trying SSH connection...";
            //connectionInfo.Timeout = TimeSpan.FromSeconds(10);
            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                if (client.IsConnected)
                {
                    lblStatus.Text = "SSH connection is active";
                    string command = ("ls -la");
                    string output = client.RunCommand(command).ToString();
                    listBox1.Text = output;
                }
                else
                {
                    lblStatus.Text = "SSH connection has failed";
                }
                //client.Disconnect();
            }
        }
Some help would be appreciated :-)

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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