从Windows机器与SSH会话交互的最简单方法?

我必须在Windows机器上编写一个应用程序(必须是windows,因为机器正在做其他的windows-y的东西),它同时通过ssh与两个不同的Tandberg单元交互。 看着他们的控制台日志stream,并对特定事件作出反应。 我需要在variables中存储一些信息,并在这两个不同的ssh会话中进行比较,或者我只是使用一些快速的securecrt脚本。

我可以很容易地使它在php(cli)中工作 – 这是我知道的一种语言,但显然对于这个项目来说并不理想。 我很擅长通过计算出新的语言来攻击我,我想我可以做.net / c# – 有没有人有一个首选的ssh .net库,不花费几百美元? 我愿意接受任何其他的build议来完成这一点。

我已成功使用plink.exe将命令发送到Linux,并从这些命令检索到基于文本的结果。

以下是你想要的:

public string ExecuteCmd() { try { string strReturn = ""; string param = ""; StreamReader standerOut; Process p = new Process(); p.StartInfo.FileName = @"plink.exe"; if (this.pass.Length == 0 || this.user.Length == 0 || this.host.Length == 0 || this.cmd.Length == 0) { throw new Exception("SSHClient: Invalid parameteres for SSHClient."); } param = "-ssh -pw " + this.pass + " " + this.user + "@" + this.host + " " + this.cmd; string cd = Environment.CurrentDirectory; if (File.Exists("plink.exe") == false) { throw new Exception("SSHClient: plink.exe not found. Make sure plink.exe is in the same folder as YOUR EXE."); } else { p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.Arguments = param; p.Start(); standerOut = p.StandardOutput; while (!p.HasExited) { if (!standerOut.EndOfStream) { strReturn += standerOut.ReadLine() + Environment.NewLine; //textBox2.SelectionStart = textBox1.Text.Length; //textBox2.ScrollToCaret(); } // Application.DoEvents(); } } return strReturn; } catch (Exception exp) { throw new Exception("SSHClient:", exp); } } 

我也使用过PLink,但是如果你想避免不得不启动另一个进程,请尝试SSH.NET:http://sshnet.codeplex.com/。

在PHP中,您可以使用SSHv2库: http : //php.net/manual/en/book.ssh2.php

要读取控制台使用ssh2_fetch_stream和执行命令使用ssh2_exec。