ObjSSH.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #import <Foundation/Foundation.h>
  2. /**
  3. * ObjSSH aims to be a full Objective-C wrapper for libssh2, with an API
  4. * that is easy to understand and fun to work with.
  5. *
  6. * To achieve that goal, the library will assume conventions but still
  7. * make it easy to override them without writing ugly code.
  8. */
  9. @interface ObjSSH : NSObject {
  10. NSString *_host;
  11. NSNumber *_port;
  12. NSString *_username;
  13. NSString *_password;
  14. NSString *_privateKey;
  15. NSString *_publicKey;
  16. }
  17. /**
  18. * Connect to a remote host with username and password
  19. *
  20. * Unless otherwise specified in the host parameter, the port is assumed to be
  21. * 22. To change port, append ":{portnr}" to the hostname.
  22. *
  23. * Examples:
  24. *
  25. * ObjSSH *ssh = [ObjSSH connectToHost:@"127.0.0.1" withUsername:@"user" password:@"pass" error:&error];
  26. * ObjSSH *ssh2 = [ObjSSH connectToHost:@"127.0.0.1:4567" withUsername:@"user" password:@"pass" error:&error];
  27. */
  28. + (id)connectToHost:(NSString *)host withUsername:(NSString *)username password:(NSString *)password error:(NSError **)error;
  29. /**
  30. * Connect to a remote host with username and public/private key pair
  31. *
  32. * Unless otherwise specified in the host parameter, the port is assumed to be
  33. * 22. To change port, append ":{portnr}" to the hostname.
  34. *
  35. * Examples:
  36. *
  37. * ObjSSH *ssh = [ObjSSH connectToHost:@"127.0.0.1" withUsername:@"user" publicKey:@"/home/user/.ssh/id_rsa.pub" privateKey:@"/home/user/.ssh/id_rsa" error:&error];
  38. */
  39. + (id)connectToHost:(NSString *)host withUsername:(NSString *)username publicKey:(NSString *)publicKey privateKey:(NSString *)privateKey error:(NSError **)error;
  40. /**
  41. * Initialize ObjSSH and set its instance variables.
  42. *
  43. * Examples:
  44. *
  45. * ObjSSH *ssh = [[ObjSSH alloc] initWithHost:@"127.0.0.1" username:@"user" password:@"pass" publicKey:nil privateKey:nil];
  46. */
  47. - (id)initWithHost:(NSString *)host username:(NSString *)username password:(NSString *)password publicKey:(NSString *)publicKey privateKey:(NSString *)priateKey;
  48. /**
  49. * Connect to a remote host. The return value is a boolean indicating whether or
  50. * not the connection succeded.
  51. *
  52. * Examples:
  53. *
  54. * NSError *error;
  55. * [ssh connect:&error];
  56. */
  57. - (BOOL)connect:(NSError **)error;
  58. /**
  59. * Disconnect from a remote host
  60. *
  61. * Examples:
  62. *
  63. * [ssh disconnect];
  64. * [ssh release];
  65. */
  66. - (void)disconnect;
  67. /**
  68. * Execute command in remote shell
  69. *
  70. * Examples:
  71. *
  72. * NSString *response = [ssh execute:@"ls -la" error:&error];
  73. */
  74. - (NSString *)execute:(NSString *)command error:(NSError **)error;
  75. /**
  76. * Upload a file to the remote server via SCP.
  77. *
  78. * Examples:
  79. *
  80. * NSError *error;
  81. * BOOL success = [ssh uploadFile:@"/path/to/local.txt" to:@"/path/to/remote.txt" error:&error];
  82. */
  83. - (BOOL)uploadFile:(NSString *)localPath to:(NSString *)remotePath error:(NSError **)error;
  84. /**
  85. * Request a file from the remote server via SCP.
  86. *
  87. * Examples:
  88. *
  89. * NSError *error;
  90. * BOOL success = [ssh downloadFile:@"/path/to/remote.txt" to:@"/path/to/local.txt" error:&error];
  91. */
  92. - (BOOL)downloadFile:(NSString *)remotePath to:(NSString *)localPath error:(NSError **)error;
  93. @end