我要做一个Windows窗体应用,单机按钮执行事件,信息都正确但是会给我返回异常
An established connection was abored by the saftwars in your host machine.
防火墙已经关闭,目标服务器监听通道正常,求各位大神帮忙解答。拜托,本人菜鸟,研究这事一周了。
private void button1_Click(object sender, EventArgs e)
{
//var File = new PrivateKeyFile();
string host = "10.11.61.27";
string username = "root";
try
{
//超时设置
var connectionInfo = new PrivateKeyConnectionInfo(host, username, new PrivateKeyFile(File.OpenRead(@"C:\Users\JIA\Desktop\cloudctrl_rsa.pri")));
//connectionInfo.Timeout = TimeSpan.FromSeconds(5);
var client = new SshClient(connectionInfo);
this.richTextBox1.AppendText("验证通过!");
client.Connect();
//创建命令对象,然后使用它来反复执行命令
var cmd = client.CreateCommand("date");
cmd.Execute();
this.richTextBox1.AppendText(cmd.Result);
cmd.Execute("ls -l");
this.richTextBox1.AppendText(cmd.Result);
this.richTextBox1.AppendText("连接成功!");
client.Disconnect();
}