SSH.NET won't allow this string

1k Views Asked by At

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(). It worked fine used putty or ssh'ing from another linux machine with the command(xnatCli) works fine. However will not work in this code instance. String length limitation on ssh.net.RunCommand() maybe? Am i doing something silly?

2

There are 2 best solutions below

0
On

try using StringBuilder instead of 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();

Hope it helps.

0
On

Try this code:

string xnatCli = "your command here";

SshCommand cmd = client.CreateCommand(xnatCli);

cmd.Execute();