cd command can't execute correctly.

Mar 27, 2012 at 9:08 AM

I download the SSH.NET library yesterday. And I  use SshClient class to write a Demo. I found that cd command do not work well.  When i execute "cd weiming", but the directory still stay in the current path. 

Coordinator
Mar 27, 2012 at 12:43 PM

Hi,

 

Can you publish code example of how you use it and where you expect the new directory to change so I could run this example here and test it?

Also, does it occur when you connect to specific server or to any server?

 

Thanks,

Oleg

Apr 27, 2012 at 5:18 PM

Hello

For each command executed, a new context is set, so a command 'cd weiming' in 1 command, and a new command 'ls' would actually not list the 'weiming' directory, but the initial directory. To change the working directory, use SshClient.ChangeDirectory() or chain multiple commands in 1 execute as such: 'cd weiming; ls', and check result for remote output.

Coordinator
Apr 27, 2012 at 6:21 PM

small correction,

Note SshClient does not have ChangeDirectory only SftpClient does.

 

Thanks,

Oleg

Jun 15, 2012 at 11:07 AM

I have the same problem cd command is not working.
I have just downloaded the lib and start to use it but when i try to change directory it will not change directory.

var client = new SshClient(root, XXXX, XXXX);
client.connect();
client.RunCommand("cd /etc/");
var cmd = client.RunCommand("pwd");
Console.WriteLine(cmd.Result);

Output:
/root

If I start a Putty and do the same it work.

Thanks,
Mats

Coordinator
Jun 18, 2012 at 1:08 PM

Hi,

 

Unfortunately command execution occurs inside unique sessions, it seems, so nothing from one command execution will be remember in the next command execution,

 

You can chain all command together in one line if needed.

 

Hope it helps.

 

Thanks,

Oleg