Stream of data through NMSSH

我的梦境 提交于 2019-12-25 07:16:22

问题


Hi I want to develop an SSH application for OSX and i have been looking into NMSSH, which is built on libssh2. How can I handle the following use case:

The application user sends a ping command to the server. => the result is continious responses

NMSSH's approach is send a command get a response and put that in a NSString, see below. But how can i handle a case with for instance ping where the response goes on and on. Do I need to use another SSH package for this functionality?

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];

回答1:


The correct answer is to use the shell functionality of the library in combination with the callback methods of channel delegate. Some issues were found in the lib but are fixed as of issue #20



来源:https://stackoverflow.com/questions/17327991/stream-of-data-through-nmssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!