iossshnmssh

NMSSH for iOS - listening and parsing data from a channel


I'm working on a iOS app which will take some inputs from user and send it to server using SSH and server acknowledges. Sending is working fine, however unable to implement listening from server side.

  1. Sending commands to server is OK. I can confirm checking on server side.
  2. How to handle acknowledgement (keep on listening) data coming from server.
  3. I want to keep the session on till user decides.
  4. iOS app store compliance - does app store has any compliance which will restrict to keep the connection on between device and server (specially in background mode).
NMSSHSession *session = [NMSSHSession connectToHost:@"127.0.0.1:22"
                                       withUsername:@"user"];

if (session.isConnected) {
    [session authenticateByPassword:@"pass"];

    if (session.isAuthorized) {
        NSLog(@"Authentication succeeded");
    }
}

NSError *error = nil;
NSString *response = [session.channel execute:@"ls -l /var/www/" error:&error];
NSLog(@"List of my sites: %@", response);

BOOL success = [session.channel uploadFile:@"~/index.html" to:@"/var/www/9muses.se/"];

[session disconnect]; //of course I want to keep the connection on all the time. 

A post on SO Stream of data through NMSSH got resolved using NMSSH shell which lead to [NMSSH Issue 20] however, but it did not help in my case.

I've seen very little tutorials and help available on this library implementation, not getting quite a right direction.


Solution

  • The following response from NMSSH Library Team. I've just tried and it's working, I'll update my answer related to other queries.

    NMSSH on GitHub (Issue No. 143) section also have lot of resources to explore on this library.

    The methods of NMSSHChannelDelegate are called when the channel is in shell mode (see startShell:) but the method execute:error: use the channel in command mode. session:didDisconnectWithError: is not called because you don't disconnect the session. Please note that session will be released at the end of serverConnect:, you should store the session in a property of CustomViewController.

    My feedback below inline.

    I used AsyncAPI another branch of NMSSH and works asynchronously to send or receive data, specially sending multiple commands is seamless now.

    1. Sending commands to server is OK. I can confirm checking on server side.
    2. How to handle acknowledgement (keep on listening) data coming from server.
      • sorted out with AsyncAPI
    3. I want to keep the session on till user decides.
      • sending heartbeat type one character dummy command to server every 15 seconds to keep the connection active till user disconnect.
    4. iOS app store compliance - does app store has any compliance which will restrict to keep the connection on between device and server (specially in background mode).
      • it does not matter anymore to my situation as sending a character in loop keeping the connection active (couple of line of Timer hack did the job.