private void send(String message) { try { OutputStream outputStream = _session.getStdin(); outputStream.write(message.getBytes()); outputStream.flush(); } catch (Exception e) { s_logger.error("Failed to send message: " + e.getMessage()); throw new CloudRuntimeException("Failed to send message: " + e.getMessage()); } }
@Override public OutputStream getOutputStream() { return ssh.getStdin(); }
public ClientDebugInputCallable(Session session, List<String> cmds, String password) { this.session = session; this.cmds = cmds; this.password = password; this.out = this.session.getStdin(); }
@Override public OutputStream getOutputStream() { return s.getStdin(); }
public OutputStream getIn() { return mySession.getStdin(); }
private void sendBytes(Session sess, byte[] data, String fileName, String mode) throws IOException { OutputStream os = sess.getStdin(); InputStream is = new BufferedInputStream(sess.getStdout(), 512); readResponse(is); String cline = "C" + mode + " " + data.length + " " + fileName + "\n"; os.write(cline.getBytes("ISO-8859-1")); os.flush(); readResponse(is); os.write(data, 0, data.length); os.write(0); os.flush(); readResponse(is); os.write("E\n".getBytes("ISO-8859-1")); os.flush(); }
private void sendBytes(Session sess, byte[] data, String fileName, String mode) throws IOException { OutputStream os = sess.getStdin(); InputStream is = new BufferedInputStream(sess.getStdout(), 512); readResponse(is); String cline = "C" + mode + " " + data.length + " " + fileName + "\n"; os.write(cline.getBytes("ISO-8859-1")); os.flush(); readResponse(is); os.write(data, 0, data.length); os.write(0); os.flush(); readResponse(is); os.write("E\n".getBytes("ISO-8859-1")); os.flush(); }
private void sendBytes(Session sess, byte[] data, String fileName, String mode) throws IOException { OutputStream os = sess.getStdin(); InputStream is = new BufferedInputStream(sess.getStdout(), 512); readResponse(is); String cline = "C" + mode + " " + data.length + " " + fileName + "\n"; os.write(cline.getBytes("ISO-8859-1")); os.flush(); readResponse(is); os.write(data, 0, data.length); os.write(0); os.flush(); readResponse(is); os.write("E\n".getBytes("ISO-8859-1")); os.flush(); }
private void initSession() { try { session = conn.openSession(); session.requestDumbPTY(); session.startShell(); stdoutReader = new BufferedReader(new InputStreamReader( session.getStdout())); stderrReader = new BufferedReader(new InputStreamReader( session.getStderr())); out = new PrintWriter(session.getStdin()); } catch (Exception e) { String msg = "\nOpen SSH2 Session Error !"; logger.error(msg, e); throw new RuntimeException(msg, e); } }
public String executeCommand(String command) { String response = null; Session session = getSession(); PrintWriter out = new PrintWriter(session.getStdin()); try { ExecutorService exec = Executors.newSingleThreadExecutor();
OutputStream os = new BufferedOutputStream(sess.getStdin(), 40000); InputStream is = new BufferedInputStream(sess.getStdout(), 512);
/** * Create a SFTP v3 client. * * @param conn The underlying SSH-2 connection to be used. * @param debug * @throws IOException * * @deprecated this constructor (debug version) will disappear in the future, * use {@link #SFTPv3Client(Connection)} instead. */ public SFTPv3Client(Connection conn, PrintStream debug) throws IOException { if (conn == null) throw new IllegalArgumentException("Cannot accept null argument!"); this.conn = conn; this.debug = debug; if (debug != null) debug.println("Opening session and starting SFTP subsystem."); sess = conn.openSession(); sess.startSubSystem("sftp"); is = sess.getStdout(); os = new BufferedOutputStream(sess.getStdin(), 2048); if ((is == null) || (os == null)) throw new IOException("There is a problem with the streams of the underlying channel."); init(); }
/** * Create a SFTP v3 client. * * @param conn The underlying SSH-2 connection to be used. * @param debug * @throws IOException * * @deprecated this constructor (debug version) will disappear in the future, * use {@link #SFTPv3Client(Connection)} instead. */ public SFTPv3Client(Connection conn, PrintStream debug) throws IOException { if (conn == null) throw new IllegalArgumentException("Cannot accept null argument!"); this.conn = conn; this.debug = debug; if (debug != null) debug.println("Opening session and starting SFTP subsystem."); sess = conn.openSession(); sess.startSubSystem("sftp"); is = sess.getStdout(); os = new BufferedOutputStream(sess.getStdin(), 2048); if ((is == null) || (os == null)) throw new IOException("There is a problem with the streams of the underlying channel."); init(); }
/** * Create a SFTP v3 client. * * @param conn The underlying SSH-2 connection to be used. * @param debug debug * @throws IOException the io exception * * @deprecated this constructor (debug version) will disappear in the future, * use {@link #SFTPv3Client(Connection)} instead. */ public SFTPv3Client(Connection conn, PrintStream debug) throws IOException { if (conn == null) throw new IllegalArgumentException("Cannot accept null argument!"); this.conn = conn; this.debug = debug; if (debug != null) debug.println("Opening session and starting SFTP subsystem."); sess = conn.openSession(); sess.startSubSystem("sftp"); is = sess.getStdout(); os = new BufferedOutputStream(sess.getStdin(), 2048); if ((is == null) || (os == null)) throw new IOException("There is a problem with the streams of the underlying channel."); init(); }
public Channel launchChannel(String[] cmd, OutputStream out, FilePath _workDir, Map<String, String> envVars) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); final Session session = connection.openSession(); session.execCommand(makeCommandLine(Arrays.asList(cmd), _workDir)); return new Channel("channel over ssh on "+connection.getHostname()+":"+connection.getPort(), Computer.threadPoolForRemoting, session.getStdout(), new BufferedOutputStream(session.getStdin())); }
public Channel launchChannel(String[] cmd, OutputStream out, FilePath _workDir, Map<String, String> envVars) throws IOException, InterruptedException { printCommandLine(cmd, _workDir); final Session session = connection.openSession(); session.execCommand(makeCommandLine(Arrays.asList(cmd), _workDir)); return new Channel("channel over ssh on "+connection.getHostname()+":"+connection.getPort(), Computer.threadPoolForRemoting, session.getStdout(), new BufferedOutputStream(session.getStdin())); }
computer.setChannel(session.getStdout(), session.getStdin(), listener.getLogger(), null); } catch (InterruptedException e) { session.close();
computer.setChannel(session.getStdout(), session.getStdin(), listener.getLogger(), null); } catch (InterruptedException e) { session.close();
/** * Executes a process remotely and blocks until its completion. * * @param command the command * @param output The stdout/stderr will be sent to this stream. * @return the int * @throws IOException the io exception * @throws InterruptedException the interrupted exception */ public int exec(String command, OutputStream output) throws IOException, InterruptedException { Session session = openSession(); try { session.execCommand(command); PumpThread t1 = new PumpThread(session.getStdout(), output); t1.start(); PumpThread t2 = new PumpThread(session.getStderr(), output); t2.start(); session.getStdin().close(); t1.join(); t2.join(); // wait for some time since the delivery of the exit status often gets delayed session.waitForCondition(ChannelCondition.EXIT_STATUS,3000); Integer r = session.getExitStatus(); if(r!=null) return r.intValue(); return -1; } finally { session.close(); } }
stdin = session.getStdin(); if (stdin == null) { throw new CommandException("Could not obtain stdin writer");