1

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

(使用通道执行单个命令:执行有效)

  -(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;
}
4

1 回答 1

0

需要启用PTY模式,库中存在一些问题(现在应该修复)

于 2013-07-01T09:50:26.253 回答