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)
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...