unfortunately, there are no async method on Scripting class for sending commands and receiving theirs output. You have to write a workaround for it. Here is a sample code:
Using ssh As Rebex.Net.Ssh = New Rebex.Net.Ssh()
Await ssh.LoginAsync(usr, pw)
Dim terminal = New Rebex.TerminalEmulation.VirtualTerminal(80, 25)
' there Is no text on screen in this point, so this call does Not matter
'sshterm.Text = string.Join("\n", terminal.Screen.GetRegionText(0, 0, terminal.Screen.Columns, terminal.Screen.Rows));
' use scripting of bound terminal
Dim scripting As Rebex.TerminalEmulation.Scripting = terminal.Scripting
' workaround for synchronous api
' detect prompt first
' if detection of prompt does not work, set the prompt directrly
'scripting.Prompt = "<prompt>" ' actual prompt
'scripting.Prompt = "regex:[Pp]rompt" ' actual prompt described with regular expression
scripting.SendCommand("17041") 'no async method
sshterm.Text = String.Join(Of String)(vbCrLf, terminal.Screen.GetRegionText(0, 0, terminal.Screen.Columns, terminal.Screen.Rows))
I also corrected some mistakes:
- ssh.StartScriptingAsync creates new VirtualTerminal, so the previous one do not receive any output to its screen.
- Also, Screen.ToString() does not convert its content to its string, you have to call Screen.GetRegionText(...) to read desired screen area.
- Before sending a command, you have to set which prompt the server uses. You can do that by calling scripting.DetectPrompt(). It can be called for prompts like '>', 'ftp>' or 'user@workingDir$ ' and similar. At the end this method sets scripting.Prompt property, so you can set this property to whatever the prompt is. That is sufficient.
- Since ssh is local variable, you should call ssh.Disconnect() or at least ssh.Dispose() when you are done with it, so I added that Using statement.