SharpSSH无法正常工作 [英] SharpSSH is not working
本文介绍了SharpSSH无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在做一个项目,目的是连接到远程计算机,执行命令并显示输出.我在C#中使用WPF项目.下面是我的代码.
Hello everyone,
I am making a project whose purpose is to connect to remote machine, execute a command and show the output. I am using WPF project in C#. and below is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tamir.SharpSsh;
using Tamir.SharpSsh.jsch;
using Tamir.Streams;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void image1_ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
}
public void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
string strval = textBox1.Text;
}
public void button2_Click(object sender, RoutedEventArgs e)
{
string host = "192.168.1.9";
string uname = "root";
string passwd = "test";
string commnd = "ls";
SshStream ssh = new SshStream(host, uname, passwd);
//Set the end of response matcher character
//Tamir.SharpSsh.SshStream (host, uname, passwd);
ssh.Prompt = "ls";
//Remove terminal emulation characters
ssh.RemoveTerminalEmulationCharacters = true;
ssh.Write(commnd+textBox1.Text);
string response = ssh.ReadResponse();
Console.Write(response);
}
public void viewbox1_show(object sender, TextChangedEventArgs e)
{
}
}
}
没有构建错误,但是当我单击按钮时,它会使程序挂起一段时间并导致错误,因此此类已知主机.
附言:目标计算机是虚拟机
我不是程序员...只是出于爱好而已,但这让我发疯,所以请别人帮忙.
问候,
There are no build errors but when I click the button it hangs the program for a while and leads to error so such known hosts.
P.S: target machine is a Virtual machine
I am not a programmer...just doing it as hobby but this is driving me nuts so please someone help.
Regards,
推荐答案
以防万一您没有解决此问题..PROMPT属性是在ssh客户端的响应中要搜索的值.通常,您会在计算机上找到[username @ machine]
In case u didn''t get this fixed.. the PROMPT property is the value that is to be searched in the response from the ssh client. Normally you will find a [username@machine]
作为命令提示符,因此必须在以下位置将提示值设置为
as being the command prompt on a machine, so you must set the prompt value to
这样的话.它知道何时找到它
in this case.. That way it knows when it finds that
这篇关于SharpSSH无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文