If you want to access raw SSH channel using low-level API, you can use IShellChannelFactory.CreateShellChannel()
method.
It can be used like this:
var ssh = new Ssh();
ssh.Connect(...);
ssh.Login(...);
var factory = (IShellChannelFactory)ssh;
var options = new TerminalOptions() { TerminalName = "vt100" };
var channel = factory.CreateShellChannel(options, 80, 24);
Using given channel
, you can use:
Poll()
- to determine state of the channel
Receive()
- to receive raw data sent by server
Send()
- to send raw data to server
Just to demonstrate how it can be used, a very simple console SSH client can be written like this:
var buffer = new byte[8 * 1024];
while (true)
{
switch (channel.Poll(50 * 1000))
{
case PollResult.NoData:
if (!Console.KeyAvailable)
break;
string command = Console.ReadLine();
byte[] commandRaw = Encoding.UTF8.GetBytes(command + "\r");
channel.Send(commandRaw, 0, commandRaw.Length);
break;
case PollResult.DataAvailable:
int n = channel.Receive(buffer, 0, buffer.Length);
Console.Write(Encoding.UTF8.GetString(buffer, 0, n));
break;
case PollResult.Closed:
Console.WriteLine("Disconnected");
return;
}
}