0

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?

PsychoData
  • 1,198
  • 16
  • 32
user3276223
  • 59
  • 1
  • 8
  • what language is this? vb.net, C+, ...? – PsychoData Feb 06 '14 at 14:47
  • at the end of the long line it says `+ "\"";` did you mean `+ """";`? or maybe just adding it to the end of the preceding string portion `12/12""";` – PsychoData Feb 06 '14 at 14:51
  • psycho...i wanted to add a " at the end of a sentence..both ways are correct..however that does not explain why it won't pass to runcommand()..cheers.. – user3276223 Feb 06 '14 at 15:20
  • So, you do need the trailing \ in your command though? your code now builds `date=12/12/12\";` Is that what you want? – PsychoData Feb 06 '14 at 16:25
  • psycho i'm using \ as an escape character I need the sentence to end with a ", ...so ...date=12/12/12" + "\" can also be date=12/12/12"""...what if i have a predefined string say sessionDate..I would have to do sessionDate + "\"";...Try it in visual c#...trust me.. – user3276223 Feb 06 '14 at 16:59
  • Anyhow thats not the problem i cannot pass the runcommand is my problem... – user3276223 Feb 06 '14 at 16:59
  • Okay. See THAT is why i asked what language this is. In vb.net you get the \ not as an escape char. You should tag that with the language – PsychoData Feb 06 '14 at 18:25

2 Answers2

0

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.

bayram
  • 64
  • 2
-1

Try this code:

string xnatCli = "your command here";

SshCommand cmd = client.CreateCommand(xnatCli);

cmd.Execute();
Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
Kazye
  • 1