/** * Creates a channel for shell type in the current session channel types = shell, sftp, exec(X * forwarding), direct-tcpip(stream forwarding) etc * * @param sshContact ID of SSH Contact */ public void createShellChannel(ContactSSH sshContact) throws IOException { try { Channel shellChannel = sshContact.getSSHSession().openChannel("shell"); // initalizing the reader and writers of ssh contact sshContact.initializeShellIO(shellChannel.getInputStream(), shellChannel.getOutputStream()); ((ChannelShell) shellChannel) .setPtyType(sshContact.getSSHConfigurationForm().getTerminalType()); // initializing the shell shellChannel.connect(1000); sshContact.setShellChannel(shellChannel); sshContact.sendLine("export PS1="); } catch (JSchException ex) { sshContact.setSSHSession(null); throw new IOException("Unable to create shell channel to remote" + " server"); } }
/** * Closes the Shell channel are associated IO Streams * * @param sshContact ID of SSH Contact */ public void closeShellChannel(ContactSSH sshContact) throws JSchException, IOException { sshContact.closeShellIO(); sshContact.getShellChannel().disconnect(); sshContact.setShellChannel(null); }