Guest User

Untitled

a guest
May 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. class Program
  2. {
  3. static byte[] ESC = { 0x1B };
  4. static byte[] UP = System.Text.ASCIIEncoding.ASCII.GetBytes("[A");
  5. static byte[] DOWN = System.Text.ASCIIEncoding.ASCII.GetBytes("[B");
  6.  
  7. static bool Runnig = true;
  8. static void Main(string[] args)
  9. {
  10.  
  11. using (var client = new SshClient("hostname", "username", "password"))
  12. {
  13. client.Connect();
  14. var stream = client.CreateShellStream("vt220", 40, 20, 800, 600, 0);
  15.  
  16. var readThread = new Thread(() =>
  17. {
  18. while (Runnig)
  19. {
  20. Console.Write(stream.Read());
  21. }
  22.  
  23. } );
  24. readThread.Start();
  25.  
  26. while (true)
  27. {
  28. var key = Console.ReadKey(true);
  29. switch(key.Key)
  30. {
  31. case ConsoleKey.A:
  32. //Why a? why not, just testing
  33. stream.Write("A");
  34. break;
  35. case ConsoleKey.Escape:
  36. //Exit and forget about it
  37. Runnig = false;
  38. client.Disconnect();
  39. return;
  40. case ConsoleKey.UpArrow:
  41. stream.Write(ESC, 0, ESC.Length);
  42. stream.Write(UP, 0, UP.Length);
  43. stream.Flush();
  44. break;
  45. case ConsoleKey.DownArrow:
  46. stream.Write(ESC, 0, ESC.Length);
  47. stream.Write(DOWN, 0, DOWN.Length);
  48. stream.Flush();
  49. break;
  50. }
  51. }
  52. }
  53.  
  54. }
  55. }
Add Comment
Please, Sign In to add comment