Search in sources :

Example 11 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project activemq-artemis by apache.

the class FTPTestSupport method setUp.

@Override
protected void setUp() throws Exception {
    if (ftpHomeDirFile.getParentFile().exists()) {
        IOHelper.deleteFile(ftpHomeDirFile.getParentFile());
    }
    ftpHomeDirFile.mkdirs();
    ftpHomeDirFile.getParentFile().deleteOnExit();
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory factory = new ListenerFactory();
    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    UserManager userManager = userManagerFactory.createUserManager();
    BaseUser user = new BaseUser();
    user.setName("activemq");
    user.setPassword("activemq");
    user.setHomeDirectory(ftpHomeDirFile.getParent());
    // authorize user
    List<Authority> auths = new ArrayList<>();
    Authority auth = new WritePermission();
    auths.add(auth);
    user.setAuthorities(auths);
    userManager.save(user);
    BaseUser guest = new BaseUser();
    guest.setName("guest");
    guest.setPassword("guest");
    guest.setHomeDirectory(ftpHomeDirFile.getParent());
    userManager.save(guest);
    serverFactory.setUserManager(userManager);
    factory.setPort(0);
    serverFactory.addListener(ftpServerListenerName, factory.createListener());
    server = serverFactory.createServer();
    server.start();
    ftpPort = serverFactory.getListener(ftpServerListenerName).getPort();
    super.setUp();
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) Authority(org.apache.ftpserver.ftplet.Authority) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) ArrayList(java.util.ArrayList) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 12 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project fess-crawler by codelibs.

the class FtpClientTest method startFtpServer.

public FtpServer startFtpServer(int port, String username, String password) throws FtpException {
    FtpServerFactory factory = new FtpServerFactory();
    ListenerFactory lisnerFactory = new ListenerFactory();
    lisnerFactory.setPort(port);
    factory.addListener("default", lisnerFactory.createListener());
    if (username != null) {
        UserManager userManager = factory.getUserManager();
        BaseUser ftpUser = new BaseUser();
        ftpUser.setName(username);
        ftpUser.setPassword(password);
        final File file = ResourceUtil.getResourceAsFile("test");
        String path = file.getAbsolutePath();
        ftpUser.setHomeDirectory(path);
        userManager.save(ftpUser);
    }
    FtpServer server = factory.createServer();
    server.start();
    return server;
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) FtpServer(org.apache.ftpserver.FtpServer) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 13 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project quickstarts by jboss-switchyard.

the class CamelFtpBindingTest method startUp.

@BeforeClass
public static void startUp() throws Exception {
    FtpServerFactory serverFactory = new FtpServerFactory();
    ListenerFactory listenerFactory = new ListenerFactory();
    listenerFactory.setPort(2222);
    serverFactory.addListener("default", listenerFactory.createListener());
    ListenerFactory sslListenerFactory = new ListenerFactory();
    sslListenerFactory.setPort(2221);
    SslConfigurationFactory ssl = new SslConfigurationFactory();
    ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
    ssl.setKeystorePassword("password");
    sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
    // Setting it to true will not read the file
    sslListenerFactory.setImplicitSsl(false);
    serverFactory.addListener("ftps", sslListenerFactory.createListener());
    PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
    managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
    managerFactory.setFile(new File("src/test/resources/users.properties"));
    UserManager createUserManager = managerFactory.createUserManager();
    serverFactory.setUserManager(createUserManager);
    NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
    fileSystemFactory.setCreateHome(true);
    serverFactory.setFileSystem(fileSystemFactory);
    File file = new File("target/ftp/ftps");
    file.mkdirs();
    file = new File("target/ftp/sftp");
    file.mkdirs();
    ftpServer = serverFactory.createServer();
    ftpServer.start();
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2220);
    sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
    sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
    sshd.setCommandFactory(new ScpCommandFactory());
    sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
    sshd.start();
    JSch sch = new JSch();
    Session session = sch.getSession("camel", "localhost", 2220);
    session.setUserInfo(new SimpleUserInfo("isMyFriend"));
    session.connect();
    ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
    c.connect();
    System.out.println("Home: " + c.getHome());
    c.chmod(777, ".");
    c.chmod(777, "target");
    c.chmod(777, "target/ftp");
    c.chmod(777, "target/ftp/sftp");
    c.disconnect();
    session.disconnect();
}
Also used : FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) NamedFactory(org.apache.sshd.common.NamedFactory) JSch(com.jcraft.jsch.JSch) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) SshServer(org.apache.sshd.SshServer) ScpCommandFactory(org.apache.sshd.server.command.ScpCommandFactory) ChannelSftp(com.jcraft.jsch.ChannelSftp) Command(org.apache.sshd.server.Command) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) ServerSession(org.apache.sshd.server.session.ServerSession) Session(com.jcraft.jsch.Session) BeforeClass(org.junit.BeforeClass)

Example 14 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project pentaho-kettle by pentaho.

the class FtpsServer method createServer.

/*
   * Adopted from https://mina.apache.org/ftpserver-project/embedding_ftpserver.html
   */
private FtpServer createServer(int port, String username, String password, boolean implicitSsl) throws Exception {
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(port);
    if (implicitSsl) {
        SslConfigurationFactory ssl = new SslConfigurationFactory();
        ssl.setKeystoreFile(new File(SERVER_KEYSTORE));
        ssl.setKeystorePassword(PASSWORD);
        // set the SSL configuration for the listener
        factory.setSslConfiguration(ssl.createSslConfiguration());
        factory.setImplicitSsl(true);
    }
    FtpServerFactory serverFactory = new FtpServerFactory();
    // replace the default listener
    serverFactory.addListener("default", factory.createListener());
    PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
    userManagerFactory.setFile(new File(SERVER_USERS));
    UserManager userManager = userManagerFactory.createUserManager();
    if (!userManager.doesExist(username)) {
        BaseUser user = new BaseUser();
        user.setName(username);
        user.setPassword(password);
        user.setEnabled(true);
        user.setHomeDirectory(USER_HOME_DIR);
        user.setAuthorities(Collections.<Authority>singletonList(new WritePermission()));
        userManager.save(user);
    }
    serverFactory.setUserManager(userManager);
    return serverFactory.createServer();
}
Also used : BaseUser(org.apache.ftpserver.usermanager.impl.BaseUser) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) UserManager(org.apache.ftpserver.ftplet.UserManager) PropertiesUserManagerFactory(org.apache.ftpserver.usermanager.PropertiesUserManagerFactory) SslConfigurationFactory(org.apache.ftpserver.ssl.SslConfigurationFactory) File(java.io.File) WritePermission(org.apache.ftpserver.usermanager.impl.WritePermission) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Example 15 with FtpServerFactory

use of org.apache.ftpserver.FtpServerFactory in project camel by apache.

the class SpringFtpEndpointTest method initFtpServer.

protected void initFtpServer() throws Exception {
    FtpServerFactory serverFactory = new FtpServerFactory();
    // setup user management to read our users.properties and use clear text passwords
    File file = new File("src/test/resources/users.properties");
    UserManager uman = new PropertiesUserManager(new ClearTextPasswordEncryptor(), file, "admin");
    serverFactory.setUserManager(uman);
    NativeFileSystemFactory fsf = new NativeFileSystemFactory();
    fsf.setCreateHome(true);
    serverFactory.setFileSystem(fsf);
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(ftpPort);
    serverFactory.addListener("default", factory.createListener());
    ftpServer = serverFactory.createServer();
}
Also used : FtpServerFactory(org.apache.ftpserver.FtpServerFactory) PropertiesUserManager(org.apache.ftpserver.usermanager.impl.PropertiesUserManager) UserManager(org.apache.ftpserver.ftplet.UserManager) NativeFileSystemFactory(org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory) File(java.io.File) PropertiesUserManager(org.apache.ftpserver.usermanager.impl.PropertiesUserManager) ClearTextPasswordEncryptor(org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory)

Aggregations

FtpServerFactory (org.apache.ftpserver.FtpServerFactory)22 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)20 UserManager (org.apache.ftpserver.ftplet.UserManager)13 File (java.io.File)11 NativeFileSystemFactory (org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory)8 ClearTextPasswordEncryptor (org.apache.ftpserver.usermanager.ClearTextPasswordEncryptor)8 BaseUser (org.apache.ftpserver.usermanager.impl.BaseUser)7 PropertiesUserManagerFactory (org.apache.ftpserver.usermanager.PropertiesUserManagerFactory)6 ConnectionConfigFactory (org.apache.ftpserver.ConnectionConfigFactory)5 PropertiesUserManager (org.apache.ftpserver.usermanager.impl.PropertiesUserManager)5 WritePermission (org.apache.ftpserver.usermanager.impl.WritePermission)5 ArrayList (java.util.ArrayList)4 Authority (org.apache.ftpserver.ftplet.Authority)4 SslConfigurationFactory (org.apache.ftpserver.ssl.SslConfigurationFactory)4 IOException (java.io.IOException)3 FtpException (org.apache.ftpserver.ftplet.FtpException)3 Listener (org.apache.ftpserver.listener.Listener)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 FtpServer (org.apache.ftpserver.FtpServer)2