iOS 的 NMSSH - 监听和解析来自频道的数据

NMSSH for iOS - listening and parsing data from a channel

我正在开发一个 iOS 应用程序,它将从用户那里获取一些输入并使用 SSH 将其发送到服务器并得到服务器确认。发送工作正常,但无法从服务器端实现监听。

  1. 向服务器发送命令是可以的。我可以在服务器端确认检查。
  2. 如何处理来自服务器的确认(继续监听)数据。
  3. 我想在用户决定之前保持会话。
  4. iOS 应用商店合规性 - 应用商店是否有任何合规性会限制保持设备和服务器之间的连接(特别是在后台模式下)。
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. 

SO Stream of data through NMSSH got resolved using NMSSH shell which lead to [NMSSH Issue 20] 上的 post 但是,但这对我的情况没有帮助。

我很少看到有关此库实现的教程和帮助,没有找到完全正确的方向。

NMSSH 图书馆团队的以下回复。我刚刚尝试过并且有效,我将更新与其他查询相关的答案。

NMSSH on GitHub (Issue No. 143) 部分也有很多资源可以探索这个库。

NMSSHChannelDelegate 的方法在通道处于 shell 模式时被调用(参见 startShell:),但是方法 execute:error:在命令模式下使用通道。 session:didDisconnectWithError: 没有被调用,因为你没有断开会话。 请注意,session 会在 serverConnect: 结束时释放,你应该将 session 存储在 CustomViewController 的 属性 中。

我的内联反馈。

我使用了 NMSSH 的另一个分支 AsyncAPI 并异步工作来发送或接收数据,特别是现在发送多个命令是无缝的。

  1. 向服务器发送命令是可以的。我可以在服务器端确认检查。
  2. 如何处理来自服务器的确认(继续监听)数据。
    • 使用 AsyncAPI 解决
  3. 我想在用户决定之前保持会话。
    • 每 15 秒向服务器发送一次 heartbeat 类型的单字符虚拟命令,以保持连接处于活动状态,直到用户断开连接。
  4. iOS 应用商店合规性 - 应用商店是否有任何合规性限制以保持设备和服务器之间的连接(特别是在后台模式下)。
    • 我的情况不再重要,因为在循环中发送一个字符以保持连接处于活动状态(几行 Timer hack 完成了这项工作。