public void startServer() { FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory factory = new ListenerFactory(); BaseUser user = new BaseUser(); user.setName("test"); user.setPassword("123456"); user.setHomeDirectory("D:/test"); int port = 2221; factory.setPort(port); // replace the default listener serverFactory.addListener("default", factory.createListener()); List<Authority> authorities = new ArrayList<Authority>(); authorities.add(new WritePermission()); user.setAuthorities(authorities); try { serverFactory.getUserManager().save(user); FtpServer server = serverFactory.createServer(); server.start(); } catch (FtpException e) { e.printStackTrace(); } }
/** * Maps a GeoServer user to an ftp {@link User} by means of the provided Spring Security's {@link * UserDetailsService}. * * <p>The user's home directory is set to the root geoserver data dir in the case of * administrators or to {@code <data dir>/incoming/<user name>} in case of non administrators. * * @see org.apache.ftpserver.ftplet.UserManager#getUserByName(java.lang.String) */ public BaseUser getUserByName(String username) throws FtpException { // basic ftp user setup BaseUser user = new BaseUser(); user.setName(username); user.setPassword(null); user.setEnabled(true); // allow writing List<Authority> authorities = new ArrayList<Authority>(); authorities.add(new WritePermission()); authorities.add(new ConcurrentLoginPermission(Integer.MAX_VALUE, Integer.MAX_VALUE)); user.setAuthorities(authorities); return user; }