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: VFSUtils.java    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 {
  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);
}
 
Example 2
@Override
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()) {
    setupModTime();

    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: FtpProviderTestCase.java    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
 * TEST_URI.
 */
@Override
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: StorageObject.java    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: java.net.ConnectException:
		 * Connection timed out (Connection timed out) at
		 * java.net.PlainSocketImpl.socketConnect(Native Method) at
		 * java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
		 * at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.
		 * java:206) at
		 * java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at
		 * java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at
		 * java.net.Socket.connect(Socket.java:589)
		 */
		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);
		ftpBuilder.setControlEncoding(opts, DefaultCharset.name);
		break;
	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);
		ftpsBuilder.setControlEncoding(opts, DefaultCharset.name);
		break;
	case cifs:
		break;
	case webdav:
		WebdavFileSystemConfigBuilder webdavBuilder = (WebdavFileSystemConfigBuilder) WebdavFileSystemConfigBuilder
				.getInstance();
		webdavBuilder.setConnectionTimeout(opts, 10000);
		webdavBuilder.setSoTimeout(opts, 10000);
		webdavBuilder.setUrlCharset(opts, DefaultCharset.name);
		// webdavBuilder.setVersioning(opts, true);
		break;
	case file:
		break;
	default:
		break;
	}
	return opts;
}