ssh-handler.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SSH Handler
  2. //
  3. // Douglas Thrift
  4. //
  5. // ssh-handler.cs
  6. /* Copyright 2013 Douglas Thrift
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using System.Diagnostics;
  21. using System.Text;
  22. public class SshHandler
  23. {
  24. public static void Main(string[] args)
  25. {
  26. foreach (string arg in args)
  27. Ssh(arg);
  28. }
  29. private static void Ssh(string arg)
  30. {
  31. System.Uri uri = new System.Uri(arg);
  32. string user = null, password = null;
  33. if (uri.UserInfo.Length != 0)
  34. {
  35. string[] userInfo = uri.UserInfo.Split(new char[] { ':' }, 2);
  36. user = userInfo[0];
  37. if (userInfo.Length == 2)
  38. password = userInfo[1];
  39. }
  40. StringBuilder args = new StringBuilder();
  41. if (password != null)
  42. args.Append("-pw ").Append(password).Append(' ');
  43. if (user != null)
  44. args.Append(user).Append('@');
  45. args.Append(uri.Host);
  46. if (uri.Port != -1)
  47. args.Append(':').Append(uri.Port);
  48. Process.Start(@"C:\Program Files (x86)\PuTTY\putty.exe", args.ToString());
  49. }
  50. }