Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static byte[] ESC = { 0x1B };
- static byte[] UP = System.Text.ASCIIEncoding.ASCII.GetBytes("[A");
- static byte[] DOWN = System.Text.ASCIIEncoding.ASCII.GetBytes("[B");
- static bool Runnig = true;
- static void Main(string[] args)
- {
- using (var client = new SshClient("hostname", "username", "password"))
- {
- client.Connect();
- var stream = client.CreateShellStream("vt220", 40, 20, 800, 600, 0);
- var readThread = new Thread(() =>
- {
- while (Runnig)
- {
- Console.Write(stream.Read());
- }
- } );
- readThread.Start();
- while (true)
- {
- var key = Console.ReadKey(true);
- switch(key.Key)
- {
- case ConsoleKey.A:
- //Why a? why not, just testing
- stream.Write("A");
- break;
- case ConsoleKey.Escape:
- //Exit and forget about it
- Runnig = false;
- client.Disconnect();
- return;
- case ConsoleKey.UpArrow:
- stream.Write(ESC, 0, ESC.Length);
- stream.Write(UP, 0, UP.Length);
- stream.Flush();
- break;
- case ConsoleKey.DownArrow:
- stream.Write(ESC, 0, ESC.Length);
- stream.Write(DOWN, 0, DOWN.Length);
- stream.Flush();
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment