Asp.net c#连接到putty SSH并运行命令行状态

本文关键字:运行 命令行 状态 SSH putty net 连接 Asp | 更新日期: 2023-09-27 18:06:32

朋友们,我看到了很多关于这个的问题,但是没有一个是我能理解的

我想做的是从asp.net c#连接到putty,然后运行命令来获取状态

然后我将使用结果每3秒绘制一个报告,并显示在我的网页上

这是我第一次尝试这样做,所以我相当无知

 private void connect_putty()
    {
        Process sh = new Process();
        sh.StartInfo.FileName = "Putty.exe";
        sh.StartInfo.UseShellExecute = false;
        sh.StartInfo.CreateNoWindow = false;
        sh.StartInfo.Arguments = "";
    }

老实说,我目前所拥有的是可怜的,任何帮助将不胜感激

Thanks in advance

Asp.net c#连接到putty SSH并运行命令行状态

建议使用Tamir.SSH。这将允许你在c#中做任何事情。

还有,我曾经写过一些代码,它可能对你有帮助。

https://github.com/daneb/Push2Linux/blob/master/Form1.cs

Sample:
 SshShell ssh; // create our shell
 ssh = new SshShell(aHost.host, aHost.username, aHost.password);
 // Command Output
  string commandoutput = string.Empty;
 // Remove Terminal Emulation Characters
  ssh.RemoveTerminalEmulationCharacters = true;
  // Connect to the remote server
  ssh.Connect();
  //Specify the character that denotes the end of response
  commandoutput = ssh.Expect(promptRegex);

PuTTY包含所有终端仿真(因此得名),所以假设您的意思是"通过ssh连接",而不是特定的PuTTY应用程序,那么ssh。. NET和SharpSSH是两个不错的选择。

c#发送一个简单的SSH命令