Hello all,
I'm using the ftp server in an embedded way. I am trying to get write 
permission for a user, unfortunately I wasn't able to make it so far.
 
1. I tried to adapt the "users.properties" file. It fails to run without that 
file, but it seems like it doesn't matter if the file is empty or not. Ideas?
 
2. I tried to set up a user manually and add write permission via the code 
(user.setAuthorities... I read this thread: 
http://www.mail-archive.com/ftpserver-users@mina.apache.org/msg01244.html ). 
Did I miss something?
 
My code (Excuse my poor programming skills, mostly c&p):
------------------------------------------------
import java.io.File;
import java.net.Inet4Address;
import java.net.UnknownHostException;
 
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.ClearTextPasswordEncryptor;
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;
 
 
 
public class ftpServer {
 
/**
     * @param args
     * @throws FtpException 
     * @throws UnknownHostException 
     */
    public static void main(String[] args) throws FtpException, 
UnknownHostException {
        FtpServerFactory serverFactory = new FtpServerFactory();
        ListenerFactory factory = new ListenerFactory();
        // set the port of the listener
        factory.setPort(2221);
        factory.setServerAddress(Inet4Address.getLocalHost().getHostAddress());
        System.out.println(Inet4Address.getLocalHost().getHostAddress());
        // replace the default listener
        serverFactory.addListener("default", factory.createListener());
        PropertiesUserManagerFactory userManagerFactory = new 
PropertiesUserManagerFactory();
        userManagerFactory.setFile(new File("users.properties"));
      
        serverFactory.setUserManager(userManagerFactory.createUserManager());
        userManagerFactory.setPasswordEncryptor(new 
ClearTextPasswordEncryptor());
        UserManager um = userManagerFactory.createUserManager();
        BaseUser user = new BaseUser();
        user.setName("ad");
        user.setPassword("min");
        user.setEnabled(true);
        user.setHomeDirectory("/Test");
        java.util.List<Authority> authorities = new 
java.util.ArrayList<Authority>();
        authorities.add(new WritePermission());
        user.setAuthorities(authorities);
        um.save(user);
        System.out.println(authorities);
        serverFactory.setUserManager(um);
        
       // start the server
        FtpServer server = serverFactory.createServer();
        server.start();
        }
 
    }

Reply via email to