List of usage examples for org.apache.commons.vfs2.provider.sftp SftpClientFactory createConnection
public static Session createConnection(final String hostname, final int port, final char[] username, final char[] password, final FileSystemOptions fileSystemOptions) throws FileSystemException
From source file:com.connection.factory.SftpConnectionApacheLib.java
@Override public boolean getConnection() { if (command != null) { closeConnection();//from ww w .j a v a2 s . c om } FileSystemOptions fso = new FileSystemOptions(); try { SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "no"); SftpFileSystemConfigBuilder.getInstance().setTimeout(fso, 5000); session = SftpClientFactory.createConnection(_ipAdress, _port, _userName.toCharArray(), _passWord.toCharArray(), fso); Channel channel = session.openChannel("sftp"); command = (ChannelSftp) channel; channel.connect(); System.out.println("Connected to " + _ipAdress + " via sFTP"); return true; } catch (FileSystemException | JSchException e) { System.out.println("Connection Failed to " + _ipAdress); return false; } }
From source file:org.pentaho.di.core.vfs.SftpFileSystemWindows.java
/** * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() } * */// w w w .j a v a 2s. c o m private void ensureSession() throws FileSystemException { if (this.session == null || !this.session.isConnected()) { this.doCloseCommunicationLink(); UserAuthenticationData authData = null; Session session; try { GenericFileName e = (GenericFileName) this.getRootName(); authData = UserAuthenticatorUtils.authenticate(this.getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(e.getHostName(), e.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(e.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(e.getPassword())), this.getFileSystemOptions()); } catch (Exception var7) { throw new FileSystemException("vfs.provider.sftp/connect.error", this.getRootName(), var7); } finally { UserAuthenticatorUtils.cleanup(authData); } this.session = session; } }