0

I am trying to set up a ftp server using apache ftp server http://mina.apache.org/ftpserver/

I want to use a file based management, and have only one user that can login. At first, I create the file this way :

String username = "ftp";
String password = "ftp";
String ftproot = "data";        

// prepares the user manager
PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory();
userManagerFactory.setFile(new File(propFile));
userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
UserManager um = userManagerFactory.createUserManager();
// set up my user
BaseUser user = new BaseUser();
user.setName(username);
user.setPassword(password);
user.setHomeDirectory(ftproot);
List<Authority> authorities = new ArrayList<Authority>();
authorities.add(new WritePermission());        
user.setAuthorities(authorities);

um.save(user);
// adds the user
serverFactory.setUserManager(um);

The file seems ok, and the ftp server works fine if I go through these steps at each startup.

What I would like is to be able to set this file once, and then just load the property file so that the user/password can be removed from the code.

I try for some time but can't get anything this way to run.

Any help would be greatly appreciated. Thank you by advance !

jlengrand
  • 12,152
  • 14
  • 57
  • 87

1 Answers1

0

Ok, once again the "tell it to your teddy bear" method worked just fine.

I found the solution two minutes after posting.

Instead of going through the all configuration dance, one just need to set the user manager.

userManagerFactory.setFile(new File(propFile));
userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor());
UserManager um = userManagerFactory.createUserManager();
serverFactory.setUserManager(um);

Here is my whole load the config method.

Hope this will help someone.

I think the apache ftp server would really need some more documentation though :S.

jlengrand
  • 12,152
  • 14
  • 57
  • 87
  • Please share your properties file. I don't know how to add user to properties file. – AZ_ Oct 15 '13 at 05:17
  • I don´t use this any more, but here is a link to an example : http://mail-archives.apache.org/mod_mbox/mina-ftpserver-users/200901.mbox/%3Cf63349b30901050106o55523c85l19aaff52346c7356@mail.gmail.com%3E. Hope this helps – jlengrand Oct 15 '13 at 08:31