正确使用NMSSH

时间:2013-06-29 15:39:36

标签: ios ssh libssh2

创建会话时,会启动shell并写入命令:没有响应,并且永远不会调用缓冲区的回调方法,我错过了什么?:

(使用channel:execute works执行单个命令)

  -(void) createSessionWithAdress:(NSString*)address username:(NSString*)user   password:(NSString*)pass{
      session = [NMSSHSession connectToHost:address withUsername:user];
      if (session.isConnected) {
        [session authenticateByPassword:pass];
      if (session.isAuthorized) {
          NSError *err = nil;
          session.channel.delegate = self;
          //self.receiveView.text = [session.channel execute:@"ls" error:&err]; // works

          [session.channel startShell:&err];
          NSLog(@"Authentication succeeded");
       }
    }
}




- (void)channel:(NMSSHChannel *)channel didReadData:(NSString *)message{
    NSLog(@"Read data!");
    receiveView.text = [NSString stringWithFormat:@"%@   \n%@",receiveView.text,message];
}

- (void)channel:(NMSSHChannel *)channel didReadError:(NSString *)error{
    receiveView.text = [NSString stringWithFormat:@"%@    \n%@",receiveView.text,error];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"RETURN PRESSED");
    NSError* err = nil;

    bool commandSucess = [session.channel write:sendView.text error:&err];
    [session.channel write:@"/n" error:&err];

    if (commandSucess) {
        NSLog(@"Command written successfully");
    }else{
        NSLog(@"Command not written successfully");
    } 
    return YES;
}

1 个答案:

答案 0 :(得分:0)

需要启用PTY模式,库中有som issues(现在应该修复)