/** * Returns a file representation * @param filePath The file path * @return a file representation */ public static FileObject resolveFileObject(String filePath) { try { if (filePath.startsWith("sftp://")) { SftpFileSystemConfigBuilder.getInstance() .setStrictHostKeyChecking(opts, "no"); } return getFileSystemManager().resolveFile(filePath, opts); } catch (FileSystemException ex) { return null; } }
/** * 获取SFTP实例 * @param host 主机 * @param port 端口 * @param user 用户 * @param password 密码 * @return * @throws FileSystemException * @throws JSchException */ public static SFTPUtils getInstance(String host, int port, String user, String password) throws FileSystemException, JSchException { FileSystemOptions vfs = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(vfs, "no"); session = SftpClientFactory.createConnection(host, port, user.toCharArray(), password.toCharArray(), vfs); Channel channel = session.openChannel("sftp"); channel.connect(); cs = (ChannelSftp) channel; return new SFTPUtils(); }
/** * 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().setStrictHostKeyChecking(opts, "no"); } else { setStrictHostKeyChecking = setStrictHostKeyChecking.trim(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, setStrictHostKeyChecking);
if (filePath.startsWith("sftp://")) { SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setStrictHostKeyChecking(opts, "no"); builder.setUserDirIsRoot(opts, false); builder.setCompression(opts, "zlib,none");
builder.setStrictHostKeyChecking(fileSystemOptions, "no"); builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo()); builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());
builder.setStrictHostKeyChecking(fileSystemOptions, "no"); builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo()); builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());
/** * 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; } }
builder.setStrictHostKeyChecking(fileSystemOptions, "no"); builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo()); builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());