/** * 打开Shell连接 * * @param session Session会话 * @return {@link ChannelShell} * @since 4.0.3 */ public static ChannelShell openShell(Session session) { Channel channel; try { channel = session.openChannel("shell"); channel.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return (ChannelShell) channel; }
/** * 打开Shell连接 * * @param session Session会话 * @return {@link ChannelShell} * @since 4.0.3 */ public static ChannelShell openShell(Session session) { Channel channel; try { channel = session.openChannel("shell"); channel.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return (ChannelShell) channel; }
/** * 打开SFTP连接 * * @param session Session会话 * @return {@link ChannelSftp} * @since 4.0.3 */ public static ChannelSftp openSftp(Session session) { Channel channel; try { channel = session.openChannel("sftp"); channel.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return (ChannelSftp) channel; }
/** * 打开SFTP连接 * * @param session Session会话 * @return {@link ChannelSftp} * @since 4.0.3 */ public static ChannelSftp openSftp(Session session) { Channel channel; try { channel = session.openChannel("sftp"); channel.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return (ChannelSftp) channel; }
public static SFTPConnection connectSftp(final SFTPConfiguration conf) throws JSchException, SftpException, IOException { final JSch jsch = new JSch(); final Session session = SFTPUtils.createSession(conf, jsch); final ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp"); sftp.connect(); return new SFTPConnection(session, sftp); }
System.out.println("session connected....."); Channel channel = session.openChannel("sftp"); channel.setInputStream(System.in); channel.setOutputStream(System.out);
/** * Create new channel every time a command needs to be executed. This is required to support execution of multiple * commands in parallel. All created channels are cleaned up when the session is closed. * * * @return a new {@link ChannelSftp} * @throws SftpException */ public ChannelSftp getSftpChannel() throws SftpException { try { ChannelSftp channelSftp = (ChannelSftp) this.session.openChannel("sftp"); channelSftp.connect(); return channelSftp; } catch (JSchException e) { throw new SftpException(0, "Cannot open a channel to SFTP server", e); } }
public void login( String password ) throws KettleJobException { this.password = password; s.setPassword( this.getPassword() ); try { java.util.Properties config = new java.util.Properties(); config.put( "StrictHostKeyChecking", "no" ); // set compression property // zlib, none String compress = getCompression(); if ( compress != null ) { config.put( COMPRESSION_S2C, compress ); config.put( COMPRESSION_C2S, compress ); } s.setConfig( config ); s.connect(); Channel channel = s.openChannel( "sftp" ); channel.connect(); c = (ChannelSftp) channel; } catch ( JSchException e ) { throw new KettleJobException( e ); } }
@Before public void setUp() throws JSchException { System.clearProperty( SFTPClient.ENV_PARAM_USERAUTH_GSSAPI ); when( server.getHostAddress() ).thenReturn( "localhost" ); when( jSch.getSession( username, "localhost", port ) ).thenReturn( session ); when( session.openChannel( "sftp" ) ).thenReturn( channel ); }
@Signature public PSSHSftpChannel sftp(Environment env) throws JSchException { return new PSSHSftpChannel(env, (ChannelSftp) getWrappedObject().openChannel("sftp")); } }
@Signature public PSSHExecChannel exec(Environment env) throws JSchException { return new PSSHExecChannel(env, (ChannelExec) getWrappedObject().openChannel("exec")); }
Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command);
session.connect(); Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setCommand(command);
/** * Create a new sftp channel to execute commands. * * @param command to execute on the remote machine * @return a new execution channel * @throws SftpException if a channel could not be opened */ public ChannelExec getExecChannel(String command) throws SftpException { ChannelExec channelExec; try { channelExec = (ChannelExec) this.session.openChannel("exec"); channelExec.setCommand(command); channelExec.connect(); return channelExec; } catch (JSchException e) { throw new SftpException(0, "Cannot open a channel to SFTP server", e); } }
String message; try { channel = session.openChannel( "exec" ); ( ( ChannelExec ) channel ).setCommand( command.getCommand() ); channel.connect();
/** * * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#executeCommand(java.lang.String, java.lang.StringBuilder) } */ private int executeCommand( String command, StringBuilder output ) throws JSchException, IOException { this.ensureSession(); ChannelExec channel = (ChannelExec) this.session.openChannel( "exec" ); channel.setCommand( command ); channel.setInputStream( (InputStream) null ); InputStreamReader stream = new InputStreamReader( channel.getInputStream() ); channel.setErrStream( System.err, true ); channel.connect(); char[] buffer = new char[128]; int read; while ( ( read = stream.read( buffer, 0, buffer.length ) ) >= 0 ) { output.append( buffer, 0, read ); } stream.close(); while ( !channel.isClosed() ) { try { Thread.sleep( 100L ); } catch ( Exception exc ) { log.logMinimal( "Warning: Error session closing. " + exc.getMessage() ); } } channel.disconnect(); return channel.getExitStatus(); }
ch = (ChannelExec)ses.openChannel("exec");
/** * Execute a command through the ssh session, pumping its * stderr and stdout to our own logs. */ private int execCommand(Session session, String cmd) throws JSchException, InterruptedException, IOException { LOG.debug("Running cmd: " + cmd); ChannelExec exec = null; try { exec = (ChannelExec)session.openChannel("exec"); exec.setCommand(cmd); exec.setInputStream(null); exec.connect(); // Pump stdout of the command to our WARN logs StreamPumper outPumper = new StreamPumper(LOG, cmd + " via ssh", exec.getInputStream(), StreamPumper.StreamType.STDOUT); outPumper.start(); // Pump stderr of the command to our WARN logs StreamPumper errPumper = new StreamPumper(LOG, cmd + " via ssh", exec.getErrStream(), StreamPumper.StreamType.STDERR); errPumper.start(); outPumper.join(); errPumper.join(); return exec.getExitStatus(); } finally { cleanup(exec); } }
channel = (ChannelExec) session.openChannel("exec"); } catch (JSchException e) { throw new JschRuntimeException(e);
channel = (ChannelExec) session.openChannel("exec"); } catch (JSchException e) { throw new JschRuntimeException(e);