org.apache.ftpserver.ftplet.FtpRequest Java Examples

The following examples show how to use org.apache.ftpserver.ftplet.FtpRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PFtpServer.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FtpletResult beforeCommand(FtpSession ftpSession, FtpRequest ftpRequest) throws FtpException, IOException {
    if (callback != null)
        callback.event("Requested command: " + ftpRequest.getCommand() + " " + ftpRequest.getArgument() + " " + ftpRequest.getRequestLine());
    return FtpletResult.DEFAULT;
}
 
Example #2
Source File: PFtpServer.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FtpletResult afterCommand(FtpSession ftpSession, FtpRequest ftpRequest, FtpReply ftpReply) throws FtpException, IOException {
    return null;
}
 
Example #3
Source File: PFtpServer.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FtpletResult onLogin(FtpSession session, FtpRequest request) throws FtpException, IOException {
    if (callback != null)
        callback.event("Logged in: " + session.getUser().getName());
    return FtpletResult.DEFAULT;
}
 
Example #4
Source File: FtpCommands.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Execute command.
 */
public void execute(final FtpIoSession session, final FtpServerContext context, final FtpRequest request) {

    // reset state variables
    session.resetState();

    String argument = request.getArgument();

    if (argument == null || argument.trim().length() == 0) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
        return;
    }

    String[] arguments = argument.split(" ", 2);

    if (arguments.length != 2) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
        return;
    }

    String timestamp = arguments[0].trim();

    try {

        Date time = DateUtils.parseFTPDate(timestamp);

        String fileName = arguments[1].trim();

        // get file object
        FtpFile file = null;

        try {
            file = session.getFileSystemView().getFile(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting the file object: " + fileName, ex);
        }

        if (file == null || !file.doesExist()) {
            session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "MFMT.filemissing", fileName));
            return;
        }

        // INFO: We want folders also to be touched
        // // check file
        // if (!file.isFile()) {
        // session.write(LocalizedFtpReply
        // .translate(
        // session,
        // request,
        // context,
        // FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
        // "MFMT.invalid", null));
        // return;
        // }

        // check if we can set date and retrieve the actual date
        // stored
        // for the file.
        if (!file.setLastModified(time.getTime())) {
            // we couldn't set the date, possibly the file was
            // locked
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "MFMT", fileName));
            return;
        }

        // all checks okay, lets go
        session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_213_FILE_STATUS, "MFMT",
                "ModifyTime=" + timestamp + "; " + fileName));

    } catch (ParseException e) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
    }

}