使用sshnet执行unix脚本

时间:2014-02-03 14:31:02

标签: c# .net ssh ssh.net

我试图通过SSH在我的UNIX机器上执行perl脚本。 我已经设法连接到机器并执行“ls”和“man chmod”,但是当我尝试“perl /test/temp.pl”或“perl a”时,我没有得到任何回报。

我使用的代码如下

PasswordConnectionInfo connectionInfo = new PasswordConnectionInfo(host, user,pass);
using (var client = new SshClient(connectionInfo))
{
    client.Connect();
    var cmd = client.CreateCommand(script);
    string result = cmd.Execute(script);
    var reader = new StreamReader(cmd.OutputStream);
    var output = reader.ReadToEnd();
    Console.Out.WriteLine(result + "_output:" + output);
}

有没有相同或类似问题的人?

1 个答案:

答案 0 :(得分:5)

尝试:

client.Connect();
SshCommand cmd = client.RunCommand(message);
var output =cmd.Result;
相关问题