使用sshnet执行Unix脚本

Sta*_*ros 1 .net c# 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);
}
Run Code Online (Sandbox Code Playgroud)

有人有相同或相似的问题吗?

Osc*_*nco 5

尝试:

client.Connect();
SshCommand cmd = client.RunCommand(message);
var output =cmd.Result;
Run Code Online (Sandbox Code Playgroud)