SharpSSH 与持久 ShellExec 连接
我正在使用 SharpSSH 连接到 SSH 服务器,并且尝试使用 SshShell 和 SshExec。 我需要能够接受一系列命令并按顺序将它们发送到服务器,因此 SshShell 并没有真正满足我的需要,因为我必须一直处理流,而且似乎有点麻烦一个拼凑品。所以我尝试过 SshExec 但发现它有一个问题,每次我发送命令时,它似乎都会建立一个新连接并丢失上一个命令的上下文。例如,如果我运行以下命令:
pwd
cd .ssh
pwd
我希望它输出
/home/adam
/home/adam/.ssh
但是,它只是两次输出“/home/adam”,这意味着目录更改在中间丢失了。
有没有一种方法可以配置它,以便它保持与 SSH 服务器的持续连接,直到我告诉它断开连接?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样做:
我不知道如何执行高级命令,但我尝试过,它输出:
Do this:
I am not sure how to do advanced commands, but I tried that and it outputs:
要 cd 到隐藏目录(任何以点 (.) 字符开头的目录),您需要将该值括在引号中。
根据文档:
简而言之,
cd '.ssh'
应该可以解决问题。To cd to a hidden directory (any directory beginning with a dot (.) character), you need to enclose the value in quotes.
According to the documentation:
In short,
cd '.ssh'
should do the trick.