对不起,如果我忽视了一些愚蠢的事情......
using (var client = new SshClient("ipaddress", "USER", "PASSWORD"))
{
client.Connect();
string xnatCli = @"XNATRestClient -host http://localhost:8080/xnat/ -u admin -p administrator -m PUT -remote ""/data/archive/projects/prj005/subjects/test12/experiments/visit12?xnat:petSessionData/date=12/12/12" + "\"";
//string list = "ls -lrt";
var cmd = client.RunCommand(xnatCli);
cmd.Execute();
var outputQuery = cmd.Result;
Console.Write(outputQuery);
Console.Read();
}
亲爱的开发者......我希望有人可以帮助我......我很想知道为什么这不起作用。我在RunCommand()中尝试了如上所示ls -lrt的简单命令。它运行良好使用putty或ssh'ing从另一台Linux机器与命令(xnatCli)工作正常。但是在此代码实例中不起作用。可能是ssh.net.RunCommand()的字符串长度限制?我在做些傻事吗?
答案 0 :(得分:0)
尝试使用StringBuilder而不是string:
StringBuilder response = new StringBuilder();
SshClient client = new SshClient("host", "user", "pass");
client.Connect();
var cmd = client.RunCommand("ls -la");
cmd.Execute();
response.Append(cmd.Result);
client.Disconnect();
希望它有所帮助。
答案 1 :(得分:-1)
试试这段代码:
string xnatCli = "your command here";
SshCommand cmd = client.CreateCommand(xnatCli);
cmd.Execute();