NMSSH for iOS - listening and analyzing data from the channel

I am working on an iOS app that will take some data from the user and send it to the server using SSH and the server will recognize. The dispatch works fine, but is unable to implement server side listening.

  • Sending commands to the server is fine. I can validate server side validation.
  • How to handle acknowledgment data (keep listening) coming from the server.
  • I want to keep the session until the user decides.
  • IOS App Store Mapping - Is there any mapping in the App Store that will restrict the connection between the device and the server (especially in the background).
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. 

      

Post on SO Data flow over NMSSH resolved using NMSSH wrapper which results in [NMSSH Issue 20] however it didn't help in my case.

I have seen very few tutorials and references available in this library implementation and not in the right direction.

+3


source to share


1 answer


The following answer is from the NMSSH library team. I just tried it and it works, I am updating my answer related to other requests.

NMSSH on GitHub ( Issue No. 143 ) also has a lot of resources to explore in this library.

Methods NMSSHChannelDelegate is called when the channel is in shell mode (see startShell :), but the method does: error: use the channel in command mode. session: didDisconnectWithError: not called because you won't disconnect the session. Note that the session will be released at the end of the serverConnect :, you must save the session in the CustomViewController property.



My feedback is below.

I used AsyncAPI another NMSSH branch and works asynchronously to send or receive data, deliberately sending multiple commands at once.

  • Sending commands to the server is fine. I can validate server side validation.
  • How to handle acknowledgment data (keep listening) coming from the server.
    • sorted with AsyncAPI
  • I want to keep the session until the user decides.
    • send a heartbeat type one character dummy command to the server every 15 seconds to keep the connection up until the user disconnects.
  • IOS App Store Mapping - Is there any mapping in the app store that will restrict the connection between the device and the server (especially in the background).
    • It doesn't matter to my situation like sending a character in a loop keeping the connection active (a couple of lines of the hack timer did the job.
+2


source







All Articles