2015-07-21 82 views
1

我試圖同時打開一個exec和SFTP通道,但是當我打開SFTP通道給我一個錯誤,代碼(簡體)是這樣的:jsch通道沒有打開

JSch connection = new JSch(); 
Session session = connection.getSession(user, ip, port); 
session.setPassword(password); 
session.connect(15000); 
ChannelExec channel = (ChannelExec) session.openChannel("exec"); 
//exec commands whit channel 
Channel ch; 
ch = ssh.session.openChannel("sftp"); 
ch.connect();//-------ERROR! 
ChannelSftp sftp = (ChannelSftp)ch; 

錯誤是:「com.jcraft.jsch.JSchException:通道未打開。」

回答

0

嘗試增加超時:

ch.connect(60 * 1000); // A minute wait for connection.