private void readStd( Session session ) throws KettleException { InputStream isOut = null; InputStream isErr = null; try { isOut = session.getStdout(); isErr = session.getStderr(); setStdOut( readInputStream( isOut ) ); setStdErr( readInputStream( isErr ) ); } catch ( Exception e ) { throw new KettleException( e ); } finally { try { if ( isOut != null ) { isOut.close(); } if ( isErr != null ) { isErr.close(); } } catch ( Exception e ) { /* Ignore */ } } }
private String receive() { String response = new String(""); InputStream inputStream = _session.getStdout();
InputStream stdout = sshSession.getStdout(); InputStream stderr = sshSession.getStderr();
InputStream stdout = sess.getStdout(); InputStream stderr = sess.getStderr();
@Override public InputStream getInputStream() { return s.getStdout(); }
@Override public InputStream getInputStream() { return ssh.getStdout(); }
public InputStream getOut() { return mySession.getStdout(); }
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 RemoteCmdClientStream(Session session, String ip) { if (session != null) { this.session = session; this.ip = ip; this.stdout = new StreamGobbler(session.getStdout()); this.stderr = new StreamGobbler(session.getStderr()); } }
/** * 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(); } }