BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
UserManager um = ((DefaultFtpServer)server).getUserManager();
BaseUser user = new BaseUser();
System.out.println("Asking for details of the new user");
System.out.println();
String userName = askForString(in, "User name:", "User name is mandatory");
if(userName == null) {
return;
}
user.setName(userName);
user.setPassword(askForString(in, "Password:"));
String home = askForString(in, "Home directory:", "Home directory is mandatory");
if(home == null) {
return;
}
user.setHomeDirectory(home);
user.setEnabled(askForBoolean(in, "Enabled (Y/N):"));
user.setMaxIdleTime(askForInt(in, "Max idle time in seconds (0 for none):"));
List<Authority> authorities = new ArrayList<Authority>();
if(askForBoolean(in, "Write permission (Y/N):")) {
authorities.add(new WritePermission());
}
int maxLogins = askForInt(in, "Maximum number of concurrent logins (0 for no restriction)");
int maxLoginsPerIp = askForInt(in, "Maximum number of concurrent logins per IP (0 for no restriction)");
authorities.add(new ConcurrentLoginPermission(maxLogins, maxLoginsPerIp));
int downloadRate = askForInt(in, "Maximum download rate (0 for no restriction)");
int uploadRate = askForInt(in, "Maximum upload rate (0 for no restriction)");
authorities.add(new TransferRatePermission(downloadRate, uploadRate));
user.setAuthorities(authorities);
um.save(user);
if(um instanceof PropertiesUserManager) {
File file = ((PropertiesUserManager) um).getFile();