C# ssh.net library, cd command does not work ( cannot send “/” )

Multi tool use
C# ssh.net library, cd command does not work ( cannot send “/” )
Every other command seems to work fine but it seems like I cannot send "/" using RunCommand() on ssh.net library. I need to change my working directory to run a program using "cd /home/debian". But when I send this line nothing seems to happen. I still stay in the home directory. How can I solve this problem?
// start the connection
var client = new SshClient (host, user,password);
client.Connect();
command = textBoxCommand.Text; //taking the command from textbox
if (command != "") //unless the command is empty
{
SshCommand sc = client.CreateCommand(command);
sc.Execute(); //run command
textBoxRecieved.AppendText(command);
textBoxRecieved.AppendText("n");
string answer = sc.Result;
answer = answer.Replace("n", " ");
textBoxRecieved.AppendText(sc.Error.Replace("n", " "));
textBoxRecieved.AppendText(answer);
textBoxRecieved.AppendText("n");
textBoxCommand.Clear();
}
}
"nothing seems to happen. I still stay in the home directory." How do you know this? Are you getting an error from the the code that you included in your question?
– Kenster
Jul 2 at 18:36
1 Answer
1
Actuallly, the cd command was working but the probllem was that every seperate command is executed from home directory. So, when I check my directory with pwd command, I see that I am still in home directory because the new command is executed at home directory.
For anyone who face this problem, you can simply send commands that needs to be executed consecutively together by:
SshCommand sc = client.CreateCommand("cd /home/debian && pwd");
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
stackoverflow.com/help/mcve - provide a minimal viable complete example.. people will need way more info
– BugFinder
Jul 2 at 12:27