/** * 打开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 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 ); } }
InputStream in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
channel.connect();
channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
channel = session.openChannel( "exec" ); ( ( ChannelExec ) channel ).setCommand( command.getCommand() ); channel.connect();
InputStream err = ((ChannelExec) channel).getErrStream(); channel.connect();
in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
InputStream in = channel.getInputStream(); channel.connect();
InputStream err = ((ChannelExec) channel).getErrStream(); channel.connect();
private ChannelSftp openSSHConnection(Server server) throws Exception { logger.debug("Opening SSH connection to {}@{}", server.getUsername(), server.getHostname()); JSch jsch = new JSch(); Session session = jsch.getSession(server.getUsername(), server.getHostname(), server.getPort()); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); if (server.getPemPath() != null) { jsch.addIdentity(server.getPemPath()); } session.setConfig(config); if (server.getPassword() != null) { session.setPassword(server.getPassword()); } session.connect(); //Open a new session for SFTP. Channel channel = session.openChannel("sftp"); channel.connect(); //checking SSH client connection. if (!channel.isConnected()) { logger.warn("Cannot connect with SSH to {}@{}", server.getUsername(), server.getHostname()); throw new RuntimeException("Can not connect to " + server.getUsername() + "@" + server.getHostname()); } logger.debug("SSH connection successful"); return (ChannelSftp) channel; } }