SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); FileSystemOptions options = new FileSystemOptions(); builder.getKnownHosts(options); builder.setUserDirIsRoot(options, false); builder.setTimeout(options, 5000); FileObject directory = manager.resolveFile("sftp://user:password@host/var/www", options);
public static FileSystemOptions buildSftpOpts(File privateKey, byte[] passPhrase) throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setUserDirIsRoot(opts, false); builder.setIdentityInfo(opts, new IdentityInfo(privateKey, passPhrase)); return opts; }
/** * Returns a file representation * * @param filePath The file path * @return a file representation * @throws FileSystemException */ public static FileObject resolveFileObject(String filePath) throws FileSystemException { LOGGER.info("Resolving file: {}", filePath); if (filePath.startsWith("sftp://")) { SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setStrictHostKeyChecking(opts, "no"); builder.setUserDirIsRoot(opts, false); builder.setCompression(opts, "zlib,none"); } else if (filePath.startsWith("smb://")) { } else if (filePath.startsWith("ftp://")) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); } UserAuthenticatorFactory factory = new UserAuthenticatorFactory(); OtrosUserAuthenticator authenticator = factory.getUiUserAuthenticator(persistentAuthStore, sessionAuthStore, filePath, opts); if (pathContainsCredentials(filePath)) { authenticator = null; } return resolveFileObject(filePath, opts, authenticator, persistentAuthStore, sessionAuthStore); }
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); } else { setUserDirIsRoot = setUserDirIsRoot.trim(); try { SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, Boolean.valueOf (setUserDirIsRoot)); } catch (Exception e) {
SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setStrictHostKeyChecking(opts, "no"); builder.setUserDirIsRoot(opts, false); builder.setCompression(opts, "zlib,none"); builder.setTimeout(opts,5000);
/** * Get the default options for File system * * @return * @throws FileSystemException */ public static FileSystemOptions createDefaultOptions() throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); // SSH Key checking SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); // Root directory set to user home SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); // Timeout is count by Milliseconds SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 100000); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, 100000); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); return opts; } }