C# ssh.net 库,cd 命令不起作用(无法发送 "/")

标签 c# ssh ssh.net

所有其他命令似乎都可以正常工作,但似乎我无法使用 ssh.net 库上的 RunCommand() 发送“/”。我需要更改工作目录以使用“cd/home/debian”运行程序。但是当我发送这条线时,似乎什么也没有发生。我仍然留在主目录中。我该如何解决这个问题?

// 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();
        }

    }

最佳答案

实际上,cd 命令可以正常工作,但问题是每个单独的命令都是从主目录执行的。因此,当我使用 pwd 命令检查我的目录时,我发现我仍在主目录中,因为新命令是在主目录中执行的。

对于遇到这个问题的任何人,您可以通过以下方式简单地发送需要连续执行的命令:

SshCommand sc = client.CreateCommand("cd /home/debian && pwd"); 

关于C# ssh.net 库,cd 命令不起作用(无法发送 "/"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51136171/

相关文章:

c# - 防止多次处理对象

docker - SSH key 不断从 Google Compute Engine VM 中删除

c# - 是否可以更改用户 SFTP 密码 (renci.sshnet)

c# - 客户端未连接异常与 SSH.Net

c# - 是否可以在网站中使用使用 IKVM 编译的 Gephi?

c# - 如何在 EWS API 上下载特定文件附件

c# - 使用模板匹配时获取匹配百分比值

linux - 限制 OpenSSH 只允许上传到特定目录

c# - 在 C# 中连接到 AWS Managed SFTP 服务器时 SSH.NET 超时

c# - 使用 SSH.NET 在进度栏中显示文件下载进度