Java Code Examples for org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder

The following examples show how to use org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: otroslogviewer   Source File:    License: Apache License 2.0 6 votes vote down vote up
 * Returns a file representation
 * @param filePath The file path
 * @return a file representation
 * @throws FileSystemException
public static FileObject resolveFileObject(String filePath) throws FileSystemException {"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);
Example 2
public void initAndConnect(
    List<Stage.ConfigIssue> issues, Source.Context context, URI remoteURI, String archiveDir
) {
  super.initAndConnect(issues, context, remoteURI, Groups.REMOTE, Groups.CREDENTIALS);

  if (issues.isEmpty()) {

    if (archiveDir != null) {
      archiveURI = UriBuilder.fromUri(remoteURI).replacePath(archiveDir).build();
      archiveOptions = (FileSystemOptions) options.clone();
      FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(archiveOptions, conf.archiveDirUserDirIsRoot);
Example 3
Source Project: commons-vfs   Source File:    License: Apache License 2.0 6 votes vote down vote up
 * Returns the base folder for tests. You can override the DEFAULT_URI by using the system property name defined by
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    String uri = getSystemTestUriOverride();
    if (uri == null) {
        uri = ConnectionUri;
    final FileSystemOptions opts = new FileSystemOptions();
    final FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
    builder.setUserDirIsRoot(opts, getUserDirIsRoot());
    builder.setPassiveMode(opts, true);
    // FtpFileType.BINARY is the default
    builder.setFileType(opts, FtpFileType.BINARY);
    builder.setConnectTimeout(opts, 10000);
    builder.setControlEncoding(opts, "UTF-8");
    return manager.resolveFile(uri, opts);
Example 4
Source Project: o2oa   Source File:    License: GNU Affero General Public License v3.0 4 votes vote down vote up
private FileSystemOptions getOptions(StorageMapping mapping) throws Exception {
	FileSystemOptions opts = new FileSystemOptions();
	if (null == mapping.getProtocol()) {
		throw new Exception("storage protocol is null.");
	switch (mapping.getProtocol()) {
	// bzip2,file, ftp, ftps, gzip, hdfs, http, https, jar, ram, res, sftp,
	// tar, temp, webdav, zip, cifs, mime;
	case ftp:
		FtpFileSystemConfigBuilder ftpBuilder = FtpFileSystemConfigBuilder.getInstance();
		 * 如果使用被动模式在阿里云centos7下会经常性出现无法连接 Caused by:
		 * Connection timed out (Connection timed out) at
		 * Method) at
		 * at
		 * java:206) at
		 * at
		 * at
		ftpBuilder.setPassiveMode(opts, Config.vfs().getFtp().getPassive());
		// builder.setPassiveMode(opts, false);
		// builder.setPassiveMode(opts, true);
		/** 强制不校验IP */
		ftpBuilder.setRemoteVerification(opts, false);
		// FtpFileType.BINARY is the default
		ftpBuilder.setFileType(opts, FtpFileType.BINARY);
		ftpBuilder.setConnectTimeout(opts, 10000);
		ftpBuilder.setSoTimeout(opts, 10000);
	case ftps:
		FtpsFileSystemConfigBuilder ftpsBuilder = FtpsFileSystemConfigBuilder.getInstance();
		ftpsBuilder.setPassiveMode(opts, Config.vfs().getFtp().getPassive());
		/** 强制不校验IP */
		ftpsBuilder.setRemoteVerification(opts, false);
		// FtpFileType.BINARY is the default
		ftpsBuilder.setFileType(opts, FtpFileType.BINARY);
		ftpsBuilder.setConnectTimeout(opts, 10000);
		ftpsBuilder.setSoTimeout(opts, 10000);
	case cifs:
	case webdav:
		WebdavFileSystemConfigBuilder webdavBuilder = (WebdavFileSystemConfigBuilder) WebdavFileSystemConfigBuilder
		webdavBuilder.setConnectionTimeout(opts, 10000);
		webdavBuilder.setSoTimeout(opts, 10000);
		// webdavBuilder.setVersioning(opts, true);
	case file:
	return opts;