简体   繁体   English

SSH.NET不允许此字符串

[英]SSH.NET won't allow this string

Sorry if i've overlooked something silly... 抱歉,如果我忽略了一些愚蠢的事情...

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();
 }

Dear developers..I'm hoping that someone can help me..I'm quite stuck for ideas to why this would not work. 亲爱的开发人员。.我希望有人能帮助我。.我非常想知道为什么这行不通。 I've tried simple commands as illustrated above ls -lrt in RunCommand(). 我已经在RunCommand()中尝试了ls -lrt上面的简单命令。 It worked fine used putty or ssh'ing from another linux machine with the command(xnatCli) works fine. 使用腻子或从另一台Linux计算机上使用ssh'ing效果很好,命令(xnatCli)正常工作。 However will not work in this code instance. 但是在此代码实例中将不起作用。 String length limitation on ssh.net.RunCommand() maybe? ssh.net.RunCommand()上的字符串长度限制可能吗? Am i doing something silly? 我在做傻事吗?

try using StringBuilder instead of string: 尝试使用StringBuilder而不是字符串:

        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();

Hope it helps. 希望能帮助到你。

Try this code: 试试这个代码:

string xnatCli = "your command here";

SshCommand cmd = client.CreateCommand(xnatCli);

cmd.Execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM