/** * 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 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("Crating SFTP Channel."); ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp"); sftpChannel.connect(); System.out.println("SFTP Channel created.");
sftp.connect(connectionTimeoutMillis); session.setTimeout(ctx.getProperty(FileTransfer.DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue()); if (!ctx.getProperty(USE_KEEPALIVE_ON_TIMEOUT).asBoolean()) {
@Override public void connect(int timeout, TimeUnit unit) throws IOException { try { ftp = (ChannelSftp) sock.openChannel("sftp"); //$NON-NLS-1$ ftp.connect((int) unit.toMillis(timeout)); } catch (JSchException e) { ftp = null; throw new IOException(e.getLocalizedMessage(), e); } }
JSch jsch = new JSch(); Session session = jsch.getSession( user, host, port ); session.setConfig( "PreferredAuthentications", "password" ); session.setPassword( pass ); session.connect( FTP_TIMEOUT ); Channel channel = session.openChannel( "sftp" ); ChannelSftp sftp = ( ChannelSftp ) channel; sftp.connect( FTP_TIMEOUT );
void connect() { try { if (!this.jschSession.isConnected()) { this.jschSession.connect(); } this.channel = (ChannelSftp) this.jschSession.openChannel("sftp"); if (this.channel != null && !this.channel.isConnected()) { this.channel.connect(); } } catch (JSchException e) { this.close(); throw new IllegalStateException("failed to connect", e); } }
private void noopConnect(ChannelSftp channel1) throws JSchException { doAnswer(invocation -> null).when(channel1).connect(); }
public synchronized ChannelSftp allocateChannelSftp() throws JSchException { ChannelSftp result; if (sftp != null) { result = sftp; sftp = null; } else { result = (ChannelSftp) session.openChannel("sftp"); result.connect(); } allocated++; return result; }
public synchronized ChannelSftp allocateChannelSftp() throws JSchException { ChannelSftp result; if (sftp != null) { result = sftp; sftp = null; } else { result = (ChannelSftp) session.openChannel("sftp"); result.connect(); } allocated++; return result; }
@Override public ChannelSftp create() throws JSchException { checkConnected(); String channel = "sftp"; sftp = (ChannelSftp) sessionConnection.getSession().openChannel(channel); sftp.connect(); return sftp; }
@Override public ChannelSftp create() throws JSchException { checkConnected(); String channel = "sftp"; sftp = (ChannelSftp) sessionConnection.getSession().openChannel(channel); sftp.connect(); return sftp; }
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); }
void connect(ChannelSftp channel) throws IOException { try { if (containsKey(CONNECT_TIMEOUT)) { int connectTimeout = FileSystemProviderSupport.getIntValue(this, CONNECT_TIMEOUT); channel.connect(connectTimeout); } else { channel.connect(); } } catch (JSchException e) { throw asFileSystemException(e); } }
public final boolean createTemporaryFile(byte[] content, String filename) throws JSchException, SftpException { ChannelSftp channel = (ChannelSftp) sesConnection.openChannel("sftp"); ByteArrayInputStream inputStream = new ByteArrayInputStream(content); channel.connect(); channel.put(inputStream, filename); channel.disconnect(); return true; }
public final boolean createFolder(String folder) throws JSchException, SftpException { ChannelSftp channel = (ChannelSftp) sesConnection.openChannel("sftp"); channel.connect(); channel.mkdir(folder); channel.disconnect(); return true; }
public static String pwd(String hostname, int port, String username, File keyFile, final String passphrase) throws JSchException, IOException, SftpException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); String pwd = channel.pwd(); channel.disconnect(); session.disconnect(); return pwd; }
public static String pwd(String hostname, int port, String username, File keyFile, final String passphrase) throws JSchException, IOException, SftpException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); String pwd = channel.pwd(); channel.disconnect(); session.disconnect(); return pwd; }
public static void uploadFile(String hostname, int port, String username, File keyFile, final String passphrase, byte[] data, String destinationFolder, String destinationFileName) throws JSchException, IOException, SftpException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); channel.cd(destinationFolder); channel.put(new ByteArrayInputStream(data), destinationFileName); channel.disconnect(); session.disconnect(); }