ssh-handler.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SSH Handler
  2. //
  3. // Douglas Thrift
  4. //
  5. // ssh-handler
  6. using System.Diagnostics;
  7. using System.Text;
  8. public class SshHandler
  9. {
  10. public static void Main(string[] args)
  11. {
  12. foreach (string arg in args)
  13. Ssh(arg);
  14. }
  15. private static void Ssh(string arg)
  16. {
  17. System.Uri uri = new System.Uri(arg);
  18. string user = null, password = null;
  19. if (uri.UserInfo.Length != 0)
  20. {
  21. string[] userInfo = uri.UserInfo.Split(new char[] { ':' }, 2);
  22. user = userInfo[0];
  23. if (userInfo.Length == 2)
  24. password = userInfo[1];
  25. }
  26. StringBuilder args = new StringBuilder();
  27. if (password != null)
  28. args.Append("-pw ").Append(password).Append(' ');
  29. if (user != null)
  30. args.Append(user).Append('@');
  31. args.Append(uri.Host);
  32. if (uri.Port != -1)
  33. args.Append(':').Append(uri.Port);
  34. Process.Start(@"C:\Program Files (x86)\PuTTY\putty.exe", args.ToString());
  35. }
  36. }