I am new to the apache ftp server and need a little help getting going with
using it for a project.  I have gone through the documentation and used the
example here:
http://mina.apache.org/ftpserver/embedding-ftpserver-in-5-minutes.html to
get a basic ftp server running.  My next step would be ensure that a test
user can log in.  I have been referencing the user management with the api
as well as other posts to this mailing list to put something together that I
think should work.  The problem is that I get a 530 Authentication Failed
message everytime I try to log in.  Also, I am creating a new listener that
should change to server over to port 2121 but it is still running on port 21
whenever I execute the code.  Any help on what I might be doing wrong would
be much appreciated.

Here is my code:

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
import org.apache.ftpserver.usermanager.SaltedPasswordEncryptor;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;

public class FTPServerSandbox {
    public FTPServerSandbox() {
        FtpServerFactory serverFactory = new FtpServerFactory();
        PropertiesUserManagerFactory userManagerFactory = new
PropertiesUserManagerFactory();
        //userManagerFactory.setFile(new File("myusers.properties"));
        userManagerFactory.setPasswordEncryptor(new
SaltedPasswordEncryptor());
        UserManager userManager = userManagerFactory.createUserManager();

        BaseUser user = new BaseUser();
        user.setName("test");
        user.setPassword("test");
        user.setHomeDirectory("C:\\Users\\Adam
Richardson\\Documents\\Eclipse\\FTPServerSandbox\\ftproot");
        List<Authority> auths = new ArrayList<Authority>();
        Authority auth = new WritePermission();
        auths.add(auth);
        user.setAuthorities(auths);
        try {
            userManager.save(user);
        } catch (FtpException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(2121);
        serverFactory.addListener("default",
listenerFactory.createListener());
        serverFactory.setUserManager(userManager);

        FtpServer server = serverFactory.createServer();
        try {
            server.start();
        } catch (FtpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Reply via email to