private void closeSession() throws IOException { session.close(); }
private void write(String cmd) throws IOException { /** Writing to the session OutputStream */ OutputStream out = session.getOutputStream(); out.write(cmd.getBytes()); }
private boolean openSession() throws IOException { open(); /** * open a new channel */ session = ssh.openSessionChannel(); /** * emulate a terminal */ session.requestPseudoTerminal("ansi", 132, 24, 132, 24, ""); return session.startShell(); }
if (sessionChannel.executeCommand(cmdToExecute.toString())) { InputStream in = sessionChannel.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // read to buffer from the stream StringBuffer buffer = new StringBuffer(); sessionChannel.getState().waitForState(ChannelState.CHANNEL_CLOSED); br.close(); ssh.disconnect();
private void flushSession(List<String> res) throws IOException { /** * Reading from the session InputStream */ InputStream in = session.getInputStream(); byte buffer[] = new byte[255]; int read; while ((read = in.read(buffer)) > 0) { String out = new String(buffer, 0, read); res.add(out); } in = session.getStderrInputStream(); buffer = new byte[255]; while ((read = in.read(buffer)) > 0) { String out = new String(buffer, 0, read); res.add(out); } }
@Override public void close() throws IOException { session.close(); super.close(); }