1

I'm using SharpSSH to connect to an SSH server and I've tried using both SshShell and SshExec. I need to be able to take a series of commands and send them to the server in order, so SshShell doesn't really do what I need since I would have to wrangle streams the whole time and it seems that it would be a bit of a kludge. So I've tried SshExec but found one problem with it, every time I send a command it seems to be making a new connection and losing the context of the last command. For example if I ran the following commands:

pwd
cd .ssh
pwd

I would expect it to output

/home/adam

/home/adam/.ssh

But, instead it just ouputs "/home/adam" both times, meaning that the directory change was lost in between.

Is there a way I can configure this so that it maintains a constant connection to the SSH server until I tell it to disconnect?

4

2 回答 2

2

做这个:

exec.RunCommand("pwd; cd Desktop; pwd")

我不确定如何执行高级命令,但我尝试了它并输出:

/Users/MyUser
/Users/MyUser/Desktop
于 2011-01-20T20:38:27.747 回答
1

要 cd 到隐藏目录(任何以点 (.) 字符开头的目录),您需要将值括在引号中。

根据文档

4) 如果目录操作数的第一个组件是点或点-点,则继续执行步骤 6。

6) 将 curpath 设置为由 PWD 的值、斜线字符和操作数连接形成的字符串。

总之,cd '.ssh'应该做的伎俩。

于 2010-06-29T15:16:02.127 回答