List of usage examples for org.apache.commons.vfs2.provider.ftp FtpFileSystemConfigBuilder getInstance
public static FtpFileSystemConfigBuilder getInstance()
From source file:com.ewcms.publication.deploy.provider.FtpDeployOperator.java
@Override protected FileObject getRootFileObject(FileSystemOptions opts, BuilderBase builder, FileSystemManager manager) throws FileSystemException { FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); String port = StringUtils.isBlank(builder.getPort()) ? DEFAULT_PORT : builder.getPort(); StringBuilder connBuilder = new StringBuilder(); connBuilder.append("ftp://"); connBuilder.append(builder.getHostname()).append(":").append(port); connBuilder.append(builder.getPath()); String conn = connBuilder.toString(); logger.debug("uri is {}", conn); return manager.resolveFile(conn, opts); }
From source file:de.blizzy.backup.vfs.ftp.FtpLocation.java
@Override protected void setFileSystemOptions(FileSystemOptions options) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true); }
From source file:net.sourceforge.fullsync.fs.filesystems.FTPAuthenticationProvider.java
@Override public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws FileSystemException { String username = description.getUsername().orElse(""); //$NON-NLS-1$ String password = description.getPassword().orElse(""); //$NON-NLS-1$ StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password); FtpFileSystemConfigBuilder cfg = FtpFileSystemConfigBuilder.getInstance(); cfg.setPassiveMode(options, true);//from w w w. j a v a 2 s .com cfg.setUserDirIsRoot(options, description.isUserDirIsRoot()); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth); }
From source file:net.sourceforge.fullsync.fs.filesystems.FTPFileSystem.java
@Override public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws FileSystemException { StaticUserAuthenticator auth = new StaticUserAuthenticator(null, description.getParameter(ConnectionDescription.PARAMETER_USERNAME), description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD)); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth); }
From source file:com.codehaus.mojo.vfs.FileSystemOptionsFactory.java
public FileSystemOptions getFileSystemOptions(String url, String username, String password) throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); String[] tokens = StringUtils.split(url, ":"); String protocol = tokens[0];/*from w w w .j a v a2 s. com*/ if ("ftp".equals(protocol)) { FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance(); builder.setPassiveMode(opts, ftpSettings.isPassiveMode()); builder.setUserDirIsRoot(opts, ftpSettings.isUserDirIsRoot()); } if ("sftp".equals(protocol)) { SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance(); builder.setUserDirIsRoot(opts, sftpSettings.isUserDirIsRoot()); } String domain = null; tokens = StringUtils.split("\\"); if (tokens.length == 2) { domain = tokens[0]; username = tokens[1]; } StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); return opts; }
From source file:com.sonicle.webtop.vfs.sfs.FtpSFS.java
@Override protected void configureOptions() throws FileSystemException { FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance(); builder.setUserDirIsRoot(fso, false); }
From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java
/** * Constructor.//from w ww . j a v a2 s .c o m * * @param options * VFS operation options * @throws NullPointerException * If given VFS operation options instance is not initiated */ public VfsFileTransferUtility(VfsOperationOptions options) { if (options == null) { throw new NullPointerException("options cannot be null"); } this.options = options; fsOptions = new FileSystemOptions(); if (options.isFtpPassiveModeEnabled()) { FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fsOptions, true); } }
From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java
public VFSMainView(ConfigBean cb, VFSFileExplorerPortlet instance) throws Exception { final String vfsUrl = cb.getVfsUrl(); if (vfsUrl.length() != 0) { removeAllComponents();/*ww w . j a v a 2 s .c o m*/ explorerPanel.setStyleName(Reindeer.PANEL_LIGHT); filePanel.setStyleName(Reindeer.PANEL_LIGHT); FileSystemOptions opts = new FileSystemOptions(); logger.log(Level.INFO, "Check Type "); if (cb.getVfsType().equalsIgnoreCase("FTP") || cb.getVfsType().equalsIgnoreCase("SFTP")) { if (cb.getUsername() != null && cb.getUsername().length() > 0) { StaticUserAuthenticator auth = new StaticUserAuthenticator(null, cb.getUsername(), cb.getPassword()); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); } } if (cb.getVfsType().equalsIgnoreCase("FTP")) { FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); } if (cb.getVfsType().equalsIgnoreCase("SFTP")) { SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); if (cb.getKeyfile() != null && cb.getKeyfile().length() > 0) { logger.log(Level.INFO, "Keyfile " + cb.getKeyfile()); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); File keyFile = new File(cb.getKeyfile()); SftpFileSystemConfigBuilder.getInstance().setIdentities(opts, new File[] { keyFile }); } SftpFileSystemConfigBuilder.getInstance().setProxyType(opts, SftpFileSystemConfigBuilder.PROXY_HTTP); if (cb.getProxyHost() != null && cb.getProxyHost().length() > 0) { SftpFileSystemConfigBuilder.getInstance().setProxyHost(opts, cb.getProxyHost()); logger.log(Level.INFO, "ProxyHost " + cb.getProxyHost()); } if (cb.getProxyPort() != null && cb.getProxyPort().length() > 0) { SftpFileSystemConfigBuilder.getInstance().setProxyPort(opts, Integer.valueOf(cb.getProxyPort())); logger.log(Level.INFO, "ProxyPort " + cb.getProxyPort()); } } DefaultFileSystemManager fsManager = null; fsManager = getManager(); final HorizontalSplitPanel panel = new HorizontalSplitPanel(); panel.setHeight(500, UNITS_PIXELS); panel.setWidth(1400, UNITS_PIXELS); panel.setSplitPosition(350, Sizeable.UNITS_PIXELS); panel.setFirstComponent(explorerPanel); panel.setSecondComponent(filePanel); addComponent(panel); final Embedded image = new Embedded(); image.setType(Embedded.TYPE_IMAGE); image.setSource(FOLDER); image.setHeight(15, Sizeable.UNITS_PIXELS); explorerPanel.setSizeFull(); filePanel.setSizeFull(); explorerPanel.addComponent(tree); filePanel.addComponent(new TableView(instance, fsManager, opts, cb)); tree.setImmediate(true); tree.addListener(new ItemClickEvent.ItemClickListener() { private static final long serialVersionUID = 1L; @Override public void itemClick(ItemClickEvent event) { VFSFileExplorerPortlet app = (VFSFileExplorerPortlet) getApplication(); String newDir = (String) event.getItemId(); app.getEventBus().fireEvent(new TableChangedEvent(newDir)); } }); scanDirectory(fsManager, opts, vfsUrl); } else { addComponent(new Label("Please configure Portlet !")); } }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
protected void initAndConnectInternal(List<Stage.ConfigIssue> issues, Source.Context context, URI remoteURI, String archiveDir) throws IOException { options = new FileSystemOptions(); this.remoteURI = remoteURI; if (conf.strictHostChecking) { issues.add(context.createConfigIssue(Groups.CREDENTIALS.getLabel(), CONF_PREFIX + "strictHostChecking", Errors.REMOTE_12));/* w ww.j a va2s.c o m*/ } switch (conf.auth) { case PRIVATE_KEY: issues.add(context.createConfigIssue(Groups.CREDENTIALS.getLabel(), CONF_PREFIX + "privateKey", Errors.REMOTE_11)); break; case PASSWORD: String username = resolveUsername(remoteURI, issues, context); String password = resolvePassword(remoteURI, issues, context); if (remoteURI.getUserInfo() != null) { remoteURI = UriBuilder.fromUri(remoteURI).userInfo(null).build(); } StaticUserAuthenticator authenticator = new StaticUserAuthenticator(remoteURI.getHost(), username, password); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator); break; case NONE: break; default: break; } FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, conf.userDirIsRoot); // Only actually try to connect and authenticate if there were no issues if (issues.isEmpty()) { LOG.info("Connecting to {}", remoteURI.toString()); // To ensure we can connect, else we fail validation. remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options); // Ensure we can assess the remote directory... remoteDir.refresh(); // throw away the results. remoteDir.getChildren(); setupModTime(); } if (archiveDir != null) { archiveURI = UriBuilder.fromUri(remoteURI).replacePath(archiveDir).build(); archiveOptions = (FileSystemOptions) options.clone(); FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(archiveOptions, conf.archiveDirUserDirIsRoot); } }
From source file:com.streamsets.pipeline.lib.remote.FTPRemoteConnector.java
@Override protected void initAndConnect(List<Stage.ConfigIssue> issues, ConfigIssueContext context, URI remoteURI, Label remoteGroup, Label credGroup) { options = new FileSystemOptions(); this.remoteURI = remoteURI; if (remoteConfig.strictHostChecking) { issues.add(context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "strictHostChecking", Errors.REMOTE_07));/* www. ja va 2 s . c om*/ } switch (remoteConfig.auth) { case PRIVATE_KEY: issues.add( context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "privateKey", Errors.REMOTE_06)); break; case PASSWORD: String username = resolveUsername(remoteURI, issues, context, credGroup); String password = resolvePassword(remoteURI, issues, context, credGroup); if (remoteURI.getUserInfo() != null) { remoteURI = UriBuilder.fromUri(remoteURI).userInfo(null).build(); } StaticUserAuthenticator authenticator = new StaticUserAuthenticator(remoteURI.getHost(), username, password); try { DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, authenticator); } catch (FileSystemException e) { // This method doesn't actually ever throw a FileSystemException, it simply declares that it does... // This shouldn't happen, but just in case, we'll log it LOG.error("Unexpected Exception", e); } break; case NONE: break; default: break; } FtpFileSystemConfigBuilder configBuilder = FtpFileSystemConfigBuilder.getInstance(); if (remoteURI.getScheme().equals(FTPS_SCHEME)) { configBuilder = FtpsFileSystemConfigBuilder.getInstance(); FtpsFileSystemConfigBuilder.getInstance().setFtpsMode(options, remoteConfig.ftpsMode.getMode()); FtpsFileSystemConfigBuilder.getInstance().setDataChannelProtectionLevel(options, remoteConfig.ftpsDataChannelProtectionLevel.getLevel()); if (remoteConfig.useFTPSClientCert) { setFtpsUserKeyManagerOrTrustManager(remoteConfig.ftpsClientCertKeystoreFile, CONF_PREFIX + "ftpsClientCertKeystoreFile", remoteConfig.ftpsClientCertKeystorePassword, CONF_PREFIX + "ftpsClientCertKeystorePassword", remoteConfig.ftpsClientCertKeystoreType, true, issues, context, credGroup); } switch (remoteConfig.ftpsTrustStoreProvider) { case FILE: setFtpsUserKeyManagerOrTrustManager(remoteConfig.ftpsTruststoreFile, CONF_PREFIX + "ftpsTruststoreFile", remoteConfig.ftpsTruststorePassword, CONF_PREFIX + "ftpsTruststorePassword", remoteConfig.ftpsTruststoreType, false, issues, context, credGroup); break; case JVM_DEFAULT: try { FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getDefaultTrustManager(null)); } catch (GeneralSecurityException e) { issues.add(context.createConfigIssue(credGroup.getLabel(), CONF_PREFIX + "ftpsTruststoreFile", Errors.REMOTE_14, "trust", "JVM", e.getMessage(), e)); } break; case ALLOW_ALL: // fall through default: FtpsFileSystemConfigBuilder.getInstance().setTrustManager(options, TrustManagerUtils.getAcceptAllTrustManager()); break; } } configBuilder.setPassiveMode(options, true); configBuilder.setUserDirIsRoot(options, remoteConfig.userDirIsRoot); // Only actually try to connect and authenticate if there were no issues if (issues.isEmpty()) { LOG.info("Connecting to {}", remoteURI.toString()); try { remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options); remoteDir.refresh(); if (remoteConfig.createPathIfNotExists && !remoteDir.exists()) { remoteDir.createFolder(); } remoteDir.getChildren(); } catch (FileSystemException e) { LOG.error(Errors.REMOTE_11.getMessage(), remoteURI.toString(), e.getMessage(), e); issues.add(context.createConfigIssue(remoteGroup.getLabel(), CONF_PREFIX + "remoteAddress", Errors.REMOTE_11, remoteURI.toString(), e.getMessage(), e)); } } }