Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.FtpFile


        if(request.getArgument() != null) {
            ListArgument parsedArg = ListArgumentParser.parse(request.getArgument());

            // check that the directory or file exists
            FtpFile file = null;
            try {
                file = session.getFileSystemView().getFile(parsedArg.getFile());
                if(!file.doesExist()) {
                    session.write(LocalizedFtpReply.translate(session, request, context,
                            FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "LIST",
                            null));            
                    return;
                }
               
                String dirList = directoryLister.listFiles(parsedArg,
                        session.getFileSystemView(), LIST_FILE_FORMATER);
               
                int replyCode;
                if(file.isDirectory()) {
                  replyCode = FtpReply.REPLY_212_DIRECTORY_STATUS;
                } else {
                  replyCode = FtpReply.REPLY_213_FILE_STATUS;
                }
               
View Full Code Here


        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < fileNames.length; i++) {
            String fileName = fileNames[i].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) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER,
                                        "MD5.invalid", fileName));
                return;
            }

            // check file
            if (!file.isFile()) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER,
                                        "MD5.invalid", fileName));
                return;
            }

            InputStream is = null;
            try {
                is = file.createInputStream(0);
                String md5Hash = md5(is);

                if (i > 0) {
                    sb.append(", ");
                }
View Full Code Here

        assertEquals("Size=13;Modify=20050202030400.000;Type=file; short\r\n",
                formater.format(TEST_FILE));
    }

    public void testSingleDir() {
        FtpFile dir = new MockFileObject() {
            public boolean isDirectory() {
                return true;
            }

            public boolean isFile() {
View Full Code Here

                    "RMD", null));
            return;
        }

        // get file object
        FtpFile file = null;
        try {
            file = session.getFileSystemView().getFile(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting file object", ex);
        }
        if (file == null) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "RMD.permission", fileName));
            return;
        }

        // check permission
        fileName = file.getAbsolutePath();
        if (!file.isRemovable()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "RMD.permission", fileName));
            return;
        }

        // check file
        if (!file.isDirectory()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "RMD.invalid", fileName));
            return;
        }

        // now delete directory
        if (file.delete()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "RMD",
                    fileName));

            // write log message
View Full Code Here

                                        "RNTO", null));
                return;
            }

            // get the "rename from" file object
            FtpFile frFile = session.getRenameFrom();
            if (frFile == null) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "RNTO",
                        null));
                return;
            }

            // get target file
            FtpFile toFile = null;
            try {
                toFile = session.getFileSystemView().getFile(toFileStr);
            } catch (Exception ex) {
                LOG.debug("Exception getting file object", ex);
            }
            if (toFile == null) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
                                        "RNTO.invalid", null));
                return;
            }
            toFileStr = toFile.getAbsolutePath();

            // check permission
            if (!toFile.isWritable()) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
                                        "RNTO.permission", null));
                return;
            }

            // check file existance
            if (!frFile.doesExist()) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_553_REQUESTED_ACTION_NOT_TAKEN_FILE_NAME_NOT_ALLOWED,
                                        "RNTO.missing", null));
                return;
            }

            // now rename
            if (frFile.move(toFile)) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "RNTO",
                        toFileStr));

                LOG.info("File rename (" + session.getUser().getName() + ") "
                        + frFile.getAbsolutePath() + " -> " + toFile.getAbsolutePath());

            } else {
                session
                        .write(LocalizedFtpReply
                                .translate(
View Full Code Here

                    "DELE", null));
            return;
        }

        // get file object
        FtpFile file = null;

        try {
            file = session.getFileSystemView().getFile(fileName);
        } catch (Exception ex) {
            LOG.debug("Could not get file " + fileName, ex);
        }
        if (file == null) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "DELE.invalid", fileName));
            return;
        }

        // check file
        fileName = file.getAbsolutePath();

        if (!file.isRemovable()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN,
                    "DELE.permission", fileName));
            return;
        }

        // now delete
        if (file.delete()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "DELE",
                    fileName));

            // log message
View Full Code Here

            session.resetState();

            String pathName = request.getArgument();

            // get filenames
            FtpFile file = null;
            try {
                String filePrefix;
                if (pathName == null) {
                    filePrefix = "ftp.dat";
                } else {
                    FtpFile dir = session.getFileSystemView().getFile(
                            pathName);
                    if (dir.isDirectory()) {
                        filePrefix = pathName + "/ftp.dat";
                    } else {
                        filePrefix = pathName;
                    }
                }
View Full Code Here

    /**
     * Get unique file object.
     */
    protected FtpFile getUniqueFile(FtpIoSession session, FtpFile oldFile)
            throws FtpException {
        FtpFile newFile = oldFile;
        FileSystemView fsView = session.getFileSystemView();
        String fileName = newFile.getAbsolutePath();
        while (newFile.doesExist()) {
            newFile = fsView.getFile(fileName + '.'
                    + System.currentTimeMillis());
            if (newFile == null) {
                break;
            }
View Full Code Here

            Date time = df.parse(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;
            }
           
            // 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;
            }

            // all checks okay, lets go
            file.setLastModified(time.getTime());

            session
            .write(LocalizedFtpReply
                    .translate(
                            session,
View Full Code Here

                                        "RETR", null));
                return;
            }

            // get file object
            FtpFile file = null;
            try {
                file = session.getFileSystemView().getFile(fileName);
            } catch (Exception ex) {
                LOG.debug("Exception getting file object", ex);
            }
            if (file == null) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "RETR.missing", fileName));
                return;
            }
            fileName = file.getAbsolutePath();

            // check file existance
            if (!file.doesExist()) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "RETR.missing", fileName));
                return;
            }

            // check valid file
            if (!file.isFile()) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "RETR.invalid", fileName));
                return;
            }

            // check permission
            if (!file.isReadable()) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "RETR.permission", fileName));
                return;
            }
View Full Code Here

TOP

Related Classes of org.apache.ftpserver.ftplet.FtpFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.