Andy, Thanks! Everything is working fine now. Regards,
Marc On Sat, May 22, 2010 at 7:56 PM, Andy Thomson <[email protected]> wrote: > Marc, > > Tried out your code snippet, changed the user file to just > "user.properties" so that it would be relative to the where code was > actually run. I tested with maven, so I created an empty file called > "user.properties" in the same directory as the pom.xml [project root]. I > made the user home to be "/tmp/bin/ftp/tmpHome". > > It worked. The user home directory was in the /tmp directory. I set the > permissions to 777 on that tree, and wrote a file via ftp. > > I changed the user home directory to be a relative path, it also worked. > The user home directory was created in the project root. > > I am suspecting that your problem is that the user.properties did not > exist. Create it in a known location, just make it an empty file. > > Here is the code: > > public class FtpTest { > > /** > * @param args the command line arguments > */ > public static void main(String[] args) throws FtpException { > > FtpServerFactory serverFactory = new FtpServerFactory(); > > ListenerFactory factory = new ListenerFactory(); > factory.setPort(2221); > serverFactory.addListener("default", > factory.createListener()); > > FtpServer server = serverFactory.createServer(); > > PropertiesUserManagerFactory userFactory = > new PropertiesUserManagerFactory(); > File userFile = new File("users.properties"); > File userHome = new File("tmp/ftp/tmpHome/"); > userHome.mkdirs(); > userFactory.setFile(userFile); > > UserManager um = userFactory.createUserManager(); > BaseUser user = new BaseUser(); > user.setName("unittest"); > user.setPassword("unittest"); > user.setHomeDirectory(userHome.getAbsolutePath()); > um.save(user); > System.out.println(user.getHomeDirectory()); > serverFactory.setUserManager(um); > System.out.println(Arrays.toString(um.getAllUserNames())); > server.start(); > } > } > > Andy > > On 05/22/2010 10:47 AM, Marc Esher wrote: >> Greetings all, >> Please pardon what is surely something very simple I'm missing. I >> need to spin up an ftp server solely for the purpose of a unit test, >> and Apache FtpServer seems like exactly what I need. Except... I'm >> having a bit of trouble with the user's permissions and home >> directory. >> >> The server starts fine, and I can log in with the user I'm creating, >> but the I get a "550 no such directory" problem on login. As I said, I >> know this is a complete "duh" thing, but I can't figure it out. >> >> Here's my sample code: >> >> >> FtpServerFactory factory = new FtpServerFactory(); >> FtpServer server = factory.createServer(); >> >> PropertiesUserManagerFactory userFactory = new >> PropertiesUserManagerFactory(); >> File userFile = new File("bin/ftp/users.properties"); >> File userHome = new File("bin/ftp/tmpHome/"); >> userHome.mkdirs(); >> userFactory.setFile(userFile); >> UserManager um = userFactory.createUserManager(); >> >> BaseUser user = new BaseUser(); >> user.setName("unittest"); >> user.setPassword("unittest"); >> user.setHomeDirectory(userHome.getAbsolutePath());//tried both >> relative and full paths... no luck >> um.save(user); >> System.out.println(user.getHomeDirectory()); >> >> >> factory.setUserManager(um); >> System.out.println( Arrays.toString(um.getAllUserNames()) ); >> >> >> server.start(); >> >> The directory exists and has some other files and directories in >> there. I thought that by logging in with a client (I'm using FileZill >> and FireFTP) I'd land in the home directory I specified in >> baseUser.setHomeDirectory(). >> >> I've tried passing relative and full paths to setHomeDirectory, each >> with the same result. >> >> Can anyone tell me the very simple thing I'm missing? Again, this is >> simply for a unit test, so I'm looking for the absolute minimum amount >> of effort to get an ftp server running for a few seconds with a single >> user to log in, CWD, and read some file attributes, and that's about >> it. >> >> Thanks so much! >> >> Marc >> >
