/** * Return the string unless it is null or empty, in which case return the defaultString. * * @param string - the String to check; may be null * @param defaultString - the value to return if string is null or empty * @return string if not null and not empty; otherwise return defaultString */ protected String defaultIfNullOrEmpty(String string, String defaultString) { return (notNullOrEmpty(string) ? string : defaultString); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.ALLO_OK, "allo"); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.SITE_OK, "site"); }
public FakeFtpServer() { setCommandHandler(CommandNames.ACCT, new AcctCommandHandler()); setCommandHandler(CommandNames.ABOR, new AborCommandHandler()); setCommandHandler(CommandNames.ALLO, new AlloCommandHandler()); setCommandHandler(CommandNames.APPE, new AppeCommandHandler()); setCommandHandler(CommandNames.CWD, new CwdCommandHandler()); setCommandHandler(CommandNames.CDUP, new CdupCommandHandler()); setCommandHandler(CommandNames.DELE, new DeleCommandHandler()); setCommandHandler(CommandNames.EPRT, new EprtCommandHandler()); setCommandHandler(CommandNames.EPSV, new EpsvCommandHandler()); setCommandHandler(CommandNames.HELP, new HelpCommandHandler()); setCommandHandler(CommandNames.LIST, new ListCommandHandler()); setCommandHandler(CommandNames.MKD, new MkdCommandHandler()); setCommandHandler(CommandNames.MODE, new ModeCommandHandler()); setCommandHandler(CommandNames.NLST, new NlstCommandHandler()); setCommandHandler(CommandNames.NOOP, new NoopCommandHandler()); setCommandHandler(CommandNames.PASS, new PassCommandHandler()); setCommandHandler(CommandNames.PASV, new PasvCommandHandler()); setCommandHandler(CommandNames.PWD, new PwdCommandHandler()); setCommandHandler(CommandNames.PORT, new PortCommandHandler()); setCommandHandler(CommandNames.QUIT, new QuitCommandHandler()); setCommandHandler(CommandNames.REIN, new ReinCommandHandler()); setCommandHandler(CommandNames.REST, new RestCommandHandler()); setCommandHandler(CommandNames.RETR, new RetrCommandHandler()); setCommandHandler(CommandNames.RMD, new RmdCommandHandler()); setCommandHandler(CommandNames.RNFR, new RnfrCommandHandler()); setCommandHandler(CommandNames.RNTO, new RntoCommandHandler()); setCommandHandler(CommandNames.SITE, new SiteCommandHandler()); setCommandHandler(CommandNames.SMNT, new SmntCommandHandler()); setCommandHandler(CommandNames.STAT, new StatCommandHandler());
protected void handle(Command command, Session session) { String currentDirectory = (String) session.getAttribute(SessionKeys.CURRENT_DIRECTORY); this.replyCodeForFileSystemException = ReplyCodes.READ_FILE_ERROR; verifyFileSystemCondition(notNullOrEmpty(currentDirectory), currentDirectory, "filesystem.currentDirectoryNotSet"); sendReply(session, ReplyCodes.PWD_OK, "pwd", list(currentDirectory)); }
protected void handle(Command command, Session session) { String systemStatus = getServerConfiguration().getSystemStatus(); sendReply(session, ReplyCodes.STAT_SYSTEM_OK, "stat", list(systemStatus)); }
protected void handle(Command command, Session session) { sendReply(session, ReplyCodes.SYST_OK, "syst", list(getServerConfiguration().getSystemName())); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.REST_OK, "rest"); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.MODE_OK, "mode"); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.STRU_OK, "stru"); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.SMNT_OK, "smnt"); }
protected void handle(Command command, Session session) { verifyLoggedIn(session); sendReply(session, ReplyCodes.ABOR_OK, "abor"); }
/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the reply code as the key. * * @param session - the Session * @param replyCode - the reply code * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode) { sendReply(session, replyCode, Collections.EMPTY_LIST); }
protected void handle(Command command, Session session) { sendReply(session, ReplyCodes.NOOP_OK, "noop"); }
/** * Verify that the current user (if any) has already logged in successfully. * * @param session - the Session */ protected void verifyLoggedIn(Session session) { if (getUserAccount(session) == null) { throw new NotLoggedInException("User has not logged in"); } }
protected void handle(Command command, Session session) { session.removeAttribute(SessionKeys.USER_ACCOUNT); sendReply(session, ReplyCodes.REIN_OK, "rein"); }
protected void handle(Command command, Session session) { sendReply(session, ReplyCodes.QUIT_OK, "quit"); session.close(); }
/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the specified messageKey. * * @param session - the Session * @param replyCode - the reply code * @param messageKey - the resource bundle key for the reply text * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode, String messageKey) { sendReply(session, replyCode, messageKey, Collections.EMPTY_LIST); }
/** * Handle the exception caught during handleCommand() * * @param command - the Command * @param session - the Session * @param exception - the caught exception * @param replyCode - the reply code that should be sent back */ private void handleException(Command command, Session session, Throwable exception, int replyCode) { LOG.warn("Error handling command: " + command + "; " + exception, exception); sendReply(session, replyCode); }
/** * Send a reply for this command on the control connection. * * <p>The reply code is designated by the <code>replyCode</code> property, and the reply text * is retrieved from the <code>replyText</code> ResourceBundle, using the reply code as the key. * * @param session - the Session * @param replyCode - the reply code * @param args - the optional message arguments; defaults to [] * @throws AssertionError - if session is null * @see MessageFormat */ protected void sendReply(Session session, int replyCode, List args) { sendReply(session, replyCode, Integer.toString(replyCode), args); }