com.jcraft.jsch.Session.openChannel()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(1222)

本文整理了Java中com.jcraft.jsch.Session.openChannel()方法的一些代码示例,展示了Session.openChannel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.openChannel()方法的具体详情如下:
包路径:com.jcraft.jsch.Session
类名称:Session
方法名:openChannel

Session.openChannel介绍

[英]Opens a new channel of some type over this connection.
[中]

代码示例

代码示例来源:origin: looly/hutool

/**
 * 打开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;
}

代码示例来源:origin: looly/hutool

/**
 * 打开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;
}

代码示例来源:origin: looly/hutool

/**
 * 打开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;
}

代码示例来源:origin: looly/hutool

/**
 * 打开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;
}

代码示例来源:origin: apache/nifi

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);
}

代码示例来源:origin: stackoverflow.com

System.out.println("session connected.....");
Channel channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);

代码示例来源:origin: apache/incubator-gobblin

/**
 * 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);
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

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 );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

@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 );
}

代码示例来源:origin: jphp-group/jphp

@Signature
  public PSSHSftpChannel sftp(Environment env) throws JSchException {
    return new PSSHSftpChannel(env, (ChannelSftp) getWrappedObject().openChannel("sftp"));
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public PSSHExecChannel exec(Environment env) throws JSchException {
  return new PSSHExecChannel(env, (ChannelExec) getWrappedObject().openChannel("exec"));
}

代码示例来源:origin: alibaba/jstorm

Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);

代码示例来源:origin: alibaba/jstorm

session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);

代码示例来源:origin: apache/incubator-gobblin

/**
 * 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);
 }
}

代码示例来源:origin: apache/usergrid

String message;
try {
  channel = session.openChannel( "exec" );
  ( ( ChannelExec ) channel ).setCommand( command.getCommand() );
  channel.connect();

代码示例来源:origin: pentaho/pentaho-kettle

/**
 *
 * {@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();
}

代码示例来源:origin: apache/ignite

ch = (ChannelExec)ses.openChannel("exec");

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * 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);
 }
}

代码示例来源:origin: looly/hutool

channel = (ChannelExec) session.openChannel("exec");
} catch (JSchException e) {
  throw new JschRuntimeException(e);

代码示例来源:origin: looly/hutool

channel = (ChannelExec) session.openChannel("exec");
} catch (JSchException e) {
  throw new JschRuntimeException(e);

相关文章

微信公众号

最新文章

更多