Renci ssh.net - 从形式创建控制台屏幕连接时 [英] Renci ssh.net - Create console screen from form when connected
问题描述
我想创建(我认为它是一个控制台)屏幕输入,看后renci ssh.net输出连接(或期间)。
目前,我有采集到的连接信息,那么你按下一个按钮,通过backgroundworker1连接一个Form1上。
我想我需要一个2并backgroundworker2保持屏幕的实时,但我不知道。
我可以创建窗体2,但不知道如何让输入和输出实时连接,一切正常了这一点。
在一般你如何创建一个输入/输出画面。
如果我至少有一个起点,我想我可以从那里走了。
公共字符串inputTo;
公共字符串outputFrom;
公共字符串服务器{搞定;组; }
公共字符串用户名{获得;组; }
公共字符串密码{搞定;组; }
公共静态SshClient客户端{搞定;组; }
公共ShellStream shellStream {搞定;组; }
公共Form1中()
{
的InitializeComponent();
}
私人无效的button1_Click(对象发件人,EventArgs五)
{
试
{
服务器= textBox1.Text;
=用户名textBox2.Text;
密码= textBox3.Text;
客户端=新SshClient(服务器,用户名,密码);
client.Connect();
串答复=的String.Empty;
shellStream = client.CreateShellStream(哑巴,80,24,800,600,1024);
回复= shellStream.Expect(新的Regex(@:* GT;#),新的时间跨度(0,0,3));
richTextBox1.Text =连接请输入command\r\\\
#;
}
赶上(异常前)
{
MessageBox.Show(ex.Message);
}
}
私人无效CheckKeys(对象发件人,System.Windows.Forms.KeyPressEventArgs E)
{
如果(e.KeyChar ==(char)的13)
{
ShellRunner();
}
}
私人无效button2_Click(对象发件人,EventArgs五)
{
client.Disconnect();
client.Dispose();
}
公共无效ShellRunner()
{
试
{
变种读者=新的StreamReader(shellStream);
INT totalLines = richTextBox1.Lines.Length;
inputTo = richTextBox1.Lines [totalLines - 2];
INT I = inputTo.LastIndexOf(#);
如果{shellStream.WriteLine(inputTo.Substring第(i + 1))(ⅰ= -1!); }
,否则{shellStream.WriteLine(inputTo); }
字符串结果= shellStream.ReadLine(新时间跨度(0,0,3));
outputFrom = reader.ReadToEnd();
richTextBox1.AppendText(outputFrom);
}
赶上(异常前)
{
MessageBox.Show(ex.ToString());
}
I would like to create (I think its a console) screen to input and see output after renci ssh.net connect (or during). I currently have a form1 which gathers the connection info then you push a button to connect through backgroundworker1.
I was thinking I would need a form2 and backgroundworker2 to keep the screen realtime but I am not sure.
I can create the form2 but not sure how to get the input and output to connect in realtime, everything works up to this point.
In general how do you create a input / output screen.
If I had at least a starting point I think I can go from there.
public string inputTo;
public string outputFrom;
public string Server { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public static SshClient client { get; set; }
public ShellStream shellStream { get; set; }
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Server = textBox1.Text;
Username = textBox2.Text;
Password = textBox3.Text;
client = new SshClient(Server, Username, Password);
client.Connect();
string reply = string.Empty;
shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024);
reply = shellStream.Expect(new Regex(@":.*>#"), new TimeSpan(0, 0, 3));
richTextBox1.Text = "Connected please enter command\r\n#";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CheckKeys(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
ShellRunner();
}
}
private void button2_Click(object sender, EventArgs e)
{
client.Disconnect();
client.Dispose();
}
public void ShellRunner()
{
try
{
var reader = new StreamReader(shellStream);
int totalLines = richTextBox1.Lines.Length;
inputTo = richTextBox1.Lines[totalLines - 2];
int i = inputTo.LastIndexOf("#");
if (i != -1){ shellStream.WriteLine(inputTo.Substring(i + 1)); }
else { shellStream.WriteLine(inputTo); }
string result = shellStream.ReadLine(new TimeSpan(0, 0, 3));
outputFrom = reader.ReadToEnd();
richTextBox1.AppendText(outputFrom);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
这篇关于Renci ssh.net - 从形式创建控制台屏幕连接时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!