org.apache.ftpserver.ftplet.FileSystemFactory Java Examples

The following examples show how to use org.apache.ftpserver.ftplet.FileSystemFactory. 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 File: FtpServer.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 创建FTP服务器
 *
 * @param listeners         服务器监听
 * @param ftplets           服务器程序
 * @param userManager       用户管理器
 * @param fileSystemFactory 文件系统工厂
 * @param commandFactory    命令工厂
 * @param messageResource   消息资源
 * @param connectionConfig  连接配置
 * @return FTP服务器
 */
public static FtpServer createServer(final Map<String, Listener> listeners,
                                     final Map<String, Ftplet> ftplets,
                                     final UserManager userManager,
                                     final FileSystemFactory fileSystemFactory,
                                     final CommandFactory commandFactory,
                                     final MessageResource messageResource,
                                     final ConnectionConfig connectionConfig) {
    final FtpServerFactory factory = new FtpServerFactory();
    factory.setListeners(listeners);
    if (ftplets != null && !ftplets.isEmpty())
        factory.setFtplets(ftplets);
    factory.setUserManager(userManager);
    factory.setFileSystem(fileSystemFactory);
    if (commandFactory != null)
        factory.setCommandFactory(commandFactory);
    if (messageResource != null)
        factory.setMessageResource(messageResource);
    factory.setConnectionConfig(connectionConfig);
    return new FtpServer(factory.createServer());
}
 
Example #2
Source File: FtpProviderUserDirTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Gets option file system factory for local FTP server.
 */
@Override
protected FileSystemFactory getFtpFileSystem() throws IOException {
    // simulate a non-root home directory by copying test directory to it
    final File testDir = new File(getTestDirectory());
    final File rootDir = new File(testDir, "homeDirIsRoot");
    final File homesDir = new File(rootDir, "home");
    final File initialDir = new File(homesDir, "test");
    FileUtils.deleteDirectory(rootDir);
    // noinspection ResultOfMethodCallIgnored
    rootDir.mkdir();
    FileUtils.copyDirectory(testDir, initialDir, pathname -> !pathname.getPath().contains(rootDir.getName()));

    return new NativeFileSystemFactory() {
        @Override
        public FileSystemView createFileSystemView(final User user) throws FtpException {
            final FileSystemView fsView = super.createFileSystemView(user);
            fsView.changeWorkingDirectory("home/test");
            return fsView;
        }
    };
}
 
Example #3
Source File: FtpProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and starts an embedded Apache FTP Server (MINA).
 *
 * @param rootDirectory the local FTP server rootDirectory
 * @param fileSystemFactory optional local FTP server FileSystemFactory
 * @throws FtpException
 * @throws IOException
 */
static void setUpClass(final String rootDirectory, final FileSystemFactory fileSystemFactory)
        throws FtpException, IOException {
    if (Server != null) {
        return;
    }
    init();
    final FtpServerFactory serverFactory = new FtpServerFactory();
    final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
    final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
    Assert.assertNotNull(USER_PROPS_RES, userPropsResource);
    propertiesUserManagerFactory.setUrl(userPropsResource);
    final UserManager userManager = propertiesUserManagerFactory.createUserManager();
    final BaseUser user = (BaseUser) userManager.getUserByName("test");
    // Pickup the home dir value at runtime even though we have it set in the user prop file
    // The user prop file requires the "homedirectory" to be set
    user.setHomeDirectory(rootDirectory);
    userManager.save(user);
    serverFactory.setUserManager(userManager);
    if (fileSystemFactory != null) {
        serverFactory.setFileSystem(fileSystemFactory);
    }
    final ListenerFactory factory = new ListenerFactory();
    // set the port of the listener
    factory.setPort(SocketPort);

    // replace the default listener
    serverFactory.addListener("default", factory.createListener());

    // start the server
    Server = serverFactory.createServer();
    Server.start();
}
 
Example #4
Source File: FtpProviderTestCase.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Gets option file system factory for local FTP server.
 */
protected FileSystemFactory getFtpFileSystem() throws IOException {
    // use default
    return null;
}