Sample: SimpleShell - Simple Shell
Executes simple commands through an SSH shell.

This utility connects to the specified SSH server and initializes a shell session.
Then it sends any command entered by the user to the server and reads the server respose character by character
to present it to the user as soon as possible.
Check out the
Using shell
and
Reading command response
tutorials for more information about the Shell class.
This sample shows:
- Using of the Ssh and Shell classes.
- Sending a command to the server.
- Reading a response from the server.
C#
// start the shell in WellKnownShell mode
Shell shell = ssh.StartShell(ShellMode.WellKnownShell);
// main loop
while (shell.Connected)
{
// output a prompt to a console
Console.Write("Enter shell command: ");
// read the command from a console
string command = Console.ReadLine();
// send the command to the server
shell.SendCommand(command);
// read the response continuously character by character until EndOfResponse is reached
for (char c = shell.ReadChar(); c != Shell.EndOfResponse; c = shell.ReadChar())
{
// output the character to a console
Console.Write(c);
}
}
VB.NET
' start the shell in WellKnownShell mode
Dim shell As Shell = ssh.StartShell(ShellMode.WellKnownShell)
' main loop
While (shell.Connected)
' output a prompt to a console
Console.Write("Enter shell command: ")
' read the command from a console
Dim command As String = Console.ReadLine()
' send the command to the server
shell.SendCommand(command)
' read the response continuously character by character until EndOfResponse is reached
Dim c As Char = shell.ReadChar()
While Not c = shell.EndOfResponse
' output the character to a console
Console.Write(c)
' read the next character
shell.ReadChar()
End While
End While
See also: