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

New Post: using SSH.Net in ASP.Net website

$
0
0
I am trying to connect to various hosts and run commands on them using SSH.NET via a asp.net website, this is what I have so far:

protected void ddlHostList_SelectedIndexChanged(object sender, EventArgs e)
{

    var hostlistID = ddlHostList.SelectedItem.Text;
    Label1.Text = hostlistID;



    if (ddlHostList.SelectedItem.Text == "Mall")
    {
        Label1.Text = SSHConnect();
    }
}
public string SSHConnect()
{
    string myData = null;

    string cmdS = "show service using-service";

    using (var ssh = new SshClient("hostIP", "username", "pwd"))
    {
            ssh.Connect();
            using (var cmd = ssh.RunCommand(cmdS))
            {
                cmd.Execute();
                myData = cmd.Result;
            }

        }
    }
    catch (Exception ex)
    {
        string str = ex.ToString();
    }


    return myData;

}
However, the command never runs and myData is always Null. Can anyone help if I am missing an important step...Thanks...

Viewing all articles
Browse latest Browse all 1729

Trending Articles



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