이 질문에 대한 답변을 많이 모았 습니다만 시작하기 좋은 방법은 없습니다.C# - SSH Winforms 콘솔을 에뮬레이트하십시오.
것은 내가 sharpssh를 사용하고 있지만 콘솔 응용 프로그램을 위해 만들어졌다. 따라서 winforms 응용 프로그램을 만들려고 할 때 원하는대로 실행할 수 없습니다.
내 양식 : 출력을 표시하는 텍스트 상자 사용자가 명령을 작성해야하는 텍스트 상자.
임은 작성한 Readline에 붙어(), I는 사용자의 입력 한 후 텍스트 상자에 삽입 된 명령을 전송 명중 할 때까지 응용 프로그램을 일시 정지 할 필요가있다. WinForm 응용 프로그램으로 응용 프로그램을 변환하는 방법을 모릅니다.그래서 질문은 이것에 대해 이동하는 방법은? - 응용 프로그램을 초기화 할 때 시작되는 프로세스와 출력이 수신되고 입력이 필요할 때 시작되는 프로세스 중 하나를 사용해야합니까? 그리고 두 번째 프로세스를 사용하여 텍스트 상자에 입력 된 이벤트 입력 키에 대한 입력 수신을 수집하고 입력을 보내고 출력을 다시 기다리는 다른 프로세스를 시작 하시겠습니까?
그렇다면 어떻게 해결할 수 있습니까?
다음 코드는 무엇입니까?
public Form1()
{
InitializeComponent();
txthost.Text = "XXX";
txtuser.Text = "XXXXX";
txtpass.Text = "XXXXX";
string pattern = "sdf:";
mPattern = pattern;
this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(checkforenter);
}
public void button1_Click(object sender, EventArgs e)
{
try
{
mShell = new SshShell(Host, User);
mShell.Password = Pass;
//WRITING USER MESSAGE
txtOutput.AppendText("Connecting...");
mShell.Connect();
txtOutput.AppendText("OK");
//txtOutput.AppendText("Enter a pattern to expect in response [e.g. '#', '$', C:\\\\.*>, etc...]: ");
//Stop for user input
mShell.ExpectPattern = mPattern;
mShell.RemoveTerminalEmulationCharacters = true;
_writer = new TextBoxStreamWriter(txtOutput);
Console.SetOut(_writer);
StringReader reader = new StringReader(txtInput.Text);
while (mShell.ShellOpened)
{
txtOutput.AppendText("\r\n" + "TERMINAL MODE ENGAGED");
txtOutput.AppendText(mShell.Expect(pattern));
txtInput.Text = Console.ReadLine();
Console.ReadLine();
Console.WriteLine(Environment.NewLine);
txtOutput.AppendText(mShell.Expect(pattern));
MessageBox.Show("innan enter 2");
Console.WriteLine(Environment.NewLine);
txtOutput.AppendText(mShell.Expect(("(continue)")));
MessageBox.Show("efter enter 2");
Console.WriteLine(Environment.NewLine);
//Data from termninal --> Append to text
string output = mShell.Expect(Pattern);
txtOutput.AppendText(output);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}