【问题标题】:asp.net c# connecting to putty ssh and running a command line like statusasp.net c# 连接到 putty ssh 并运行类似状态的命令行
【发布时间】:2016-04-29 07:40:53
【问题描述】:

好吧,伙计们,我已经看到了很多关于这个的问题,但没有一个我可以使用或理解

我正在尝试做的是从 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 = "";
    }

说实话,我目前拥有的东西很可悲,任何帮助都将不胜感激

提前致谢

【问题讨论】:

  • 你到底想让 Putty 做什么?连接到远程主机?
  • 您能否说明您是想通过 SSH 连接到服务器,还是真的想启动 putty 并连接到服务器?
  • @adrian 我通常会运行一个命令从 ip(是主机)获取状态,然后我想检索信息并绘制一个我将在网页上显示的图表
  • @Dane 老实说,我想用我的 c# 代码做所有事情,但我不知道这是否可能,因此如果你知道一种我欣赏它的方法,我会尝试启动 putty
  • 这听起来像是你想连接到一个 SSH 服务器,然后执行一个命令,返回它的结果,然后绘制它。啊!然后你需要一个 C# OpenSSH API,它可以让你绕过 Putty 并自己与服务器对话

标签: c# asp.net ssh


【解决方案1】:

我建议使用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);

【讨论】:

  • 我能否获得每 3 秒更新一次网站图表的结果?
【解决方案2】:

PuTTY 包括所有终端仿真(因此得名),因此假设您的意思是“通过 ssh 连接”,而不是专门的 putty 应用程序,那么 SSH.NETSharpSSH 是两个不错的选择。

查看这个相关问题:C# send a simple SSH command

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多