本文整理汇总了Java中org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder类的典型用法代码示例。如果您正苦于以下问题:Java FtpFileSystemConfigBuilder类的具体用法?Java FtpFileSystemConfigBuilder怎么用?Java FtpFileSystemConfigBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FtpFileSystemConfigBuilder类属于org.apache.commons.vfs2.provider.ftp包,在下文中一共展示了FtpFileSystemConfigBuilder类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WatchFTPRunner
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
public WatchFTPRunner(FTPConfig config) {
this.config = config;
try {
fsManager = VFS.getManager();
UserAuthenticator auth = new StaticUserAuthenticator("", config.getConnection().getUsername(), config.getConnection().getPassword());
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts,true);
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
resolvedAbsPath = fsManager.resolveFile(config.getFolder() + config.getConnection().getPathtomonitor() , opts);
log.info("Connection successfully established to " + resolvedAbsPath.getPublicURIString());
log.debug("Exists: " + resolvedAbsPath.exists());
log.debug("Type : " + resolvedAbsPath.getType());
} catch (FileSystemException e) {
log.error("File system exception for " + config.getFolder(), e);
//throw here?
}
}
示例2: resolveFileObject
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* 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);
}
示例3: createDefaultOptions
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* 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;
}
示例4: createStorageProvider
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public StorageProvider createStorageProvider(Map<String, ? extends Object> properties) {
String ftpUrl = normalize(properties);
try {
FileSystemManager fsManager = VFS.getManager();
FileSystemOptions opts = new FileSystemOptions();
FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
FileObject fileObject = fsManager.resolveFile(ftpUrl, opts);
boolean createDirectory = getBoolean(properties, FtpStorage.CREATE_DIRECTORY_PROPERTY, false);
fsManager.getFilesCache().clear(fileObject.getFileSystem());
if (!fileObject.exists()) {
if (createDirectory) {
fileObject.createFolder();
} else {
throw new StorageException("The given base path does not resolve to an existing directory: " + ftpUrl);
}
}
if (fileObject.getType() != FileType.FOLDER) {
throw new StorageException("The given base path does not resolve to an existing directory: " + ftpUrl);
}
// TODO: Maybe try to create a little test object so we can self check if writing is allowed
boolean supportsWriting = true;
return new FtpStorageProvider(fileObject, supportsWriting);
} catch (FileSystemException ex) {
throw new StorageException("Could not connect to the ftp storage at: " + ftpUrl, ex);
}
}
示例5: VFSClientConnectorImpl
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
public VFSClientConnectorImpl(Map<String, String> connectorConfig,
RemoteFileSystemListener remoteFileSystemListener) {
this.connectorConfig = connectorConfig;
this.remoteFileSystemListener = remoteFileSystemListener;
if (Constants.PROTOCOL_FTP.equals(connectorConfig.get(Constants.PROTOCOL))) {
connectorConfig.forEach((property, value) -> {
// TODO: Add support for other FTP related configurations
if (Constants.FTP_PASSIVE_MODE.equals(property)) {
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, Boolean.parseBoolean(value));
}
});
}
}
示例6: RemoteFileSystemConsumer
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Constructor for the RemoteFileSystemConsumer.
*
* @param id Name of the service that creates the consumer
* @param fileProperties Map of property values
* @param listener RemoteFileSystemListener instance to send callback
* @throws RemoteFileSystemConnectorException if unable to start the connect to the remote server
*/
public RemoteFileSystemConsumer(String id, Map<String, String> fileProperties, RemoteFileSystemListener listener)
throws RemoteFileSystemConnectorException {
this.serviceName = id;
this.fileProperties = fileProperties;
this.remoteFileSystemListener = listener;
setupParams();
try {
fsManager = VFS.getManager();
Map<String, String> options = parseSchemeFileOptions(listeningDirURI);
fso = FileTransportUtils.attachFileSystemOptions(options, fsManager);
// TODO: Make this and other file related configurations configurable
if (options != null && Constants.SCHEME_FTP.equals(options.get(Constants.SCHEME))) {
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(fso, true);
}
listeningDir = fsManager.resolveFile(listeningDirURI, fso);
if (!listeningDir.isWriteable()) {
postProcessAction = Constants.ACTION_NONE;
}
FileType fileType = getFileType(listeningDir);
if (fileType != FileType.FOLDER) {
String errorMsg = "[" + serviceName + "] File system server connector is used to " +
"listen to a folder. But the given path does not refer to a folder.";
final RemoteFileSystemConnectorException exception
= new RemoteFileSystemConnectorException(errorMsg);
remoteFileSystemListener.onError(exception);
throw exception;
}
//Initialize the thread executor based on properties
threadPool = new ThreadPoolFactory(threadPoolSize);
} catch (FileSystemException e) {
remoteFileSystemListener.onError(e);
throw new RemoteFileSystemConnectorException("[" + serviceName + "] Unable to initialize " +
"the connection with server.", e);
}
}
示例7: init
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public Object init(CarbonMessage cMsg, CarbonCallback callback, Map<String, Object> properties)
throws ClientConnectorException {
//TODO: Handle FS options configuration for other protocols as well
if (Constants.PROTOCOL_FTP.equals(properties.get("PROTOCOL"))) {
properties.forEach((property, value) -> {
// TODO: Add support for other FTP related configurations
if (Constants.FTP_PASSIVE_MODE.equals(property)) {
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, (Boolean) value);
}
});
}
return Boolean.TRUE;
}
示例8: FileToFtpCommandHandler
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
public FileToFtpCommandHandler(String ftpPath) {
this.ftpPath = ftpPath;
FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
FileSystemOptions opts = new FileSystemOptions();
builder.setPassiveMode(opts, true);
builder.setUserDirIsRoot(opts, true);
try {
this.fileSystemManager = VFS.getManager();
} catch (FileSystemException e) {
LOGGER.error("failed create fileSystemManager");
throw new RuntimeException("failed create fileSystemManager");
}
}
示例9: execute
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public void execute() {
FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
FileSystemOptions opts = new FileSystemOptions();
builder.setPassiveMode(opts, true);
builder.setUserDirIsRoot(opts, true);
try {
FileSystemManager fileSystemManager = VFS.getManager();
dest.copyFrom(src, Selectors.SELECT_SELF);
System.out.println("upload " + src.getName().getBaseName());
} catch (FileSystemException e) {
e.printStackTrace();
}
}
示例10: testFileObject
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
@Test
public void testFileObject() throws IOException {
FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
FileSystemOptions opts = new FileSystemOptions();
builder.setPassiveMode(opts, true);
builder.setUserDirIsRoot(opts, true);
FileSystemManager fileSystemManager = VFS.getManager();
FileObject srcFolder = fileSystemManager.resolveFile("file://f:/camelinaction-master");
if (!FileType.FOLDER.equals(srcFolder.getType())) {
throw new IllegalArgumentException("源路径必须是文件夹");
}
FileObject destFile = fileSystemManager.resolveFile("ftp://10.4.14.14/temp/zyz/", opts);
destFile.copyFrom(srcFolder, Selectors.EXCLUDE_SELF);
}
示例11: getBaseTestFolder
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
/**
* Returns the base folder for tests.
*/
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception
{
final String uri = System.getProperty(TEST_URI);
FileSystemOptions opts = new FileSystemOptions();
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
return manager.resolveFile(uri, opts);
}
示例12: authSetup
import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder; //导入依赖的package包/类
@Override
public final void authSetup(final ConnectionDescription description, final FileSystemOptions options) throws FileSystemException {
String username = description.getParameter(ConnectionDescription.PARAMETER_USERNAME);
String password = description.getSecretParameter(ConnectionDescription.PARAMETER_PASSWORD);
StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(options, true);
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
}