1
正确用法当创建一个会话,一个shell启动并命令写入:不回应是收到和缓冲区的回调方法不会被调用,我错过了什么?:的NMSSH
(执行一单命令使用信道:执行作品)
-(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;
}