小编Giz*_*zem的帖子

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

所有其他命令似乎都可以正常工作,但似乎我无法在 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();
        }

    }
Run Code Online (Sandbox Code Playgroud)

c# ssh ssh.net

1
推荐指数
1
解决办法
1507
查看次数

标签 统计

c# ×1

ssh ×1

ssh.net ×1