Examples of FTPFile


Examples of org.apache.ftpserver.ftplet.FtpFile

     * Get unique file object.
     */
    //TODO may need synchronization
    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

Examples of org.apache.ftpserver.ftplet.FtpFile

            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;
            }
           
            // 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;
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

                    "MKD", null, 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(LocalizedFileActionFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "MKD.invalid", fileName, file));
            return;
        }

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

        // check file existance
        if (file.doesExist()) {
            session.write(LocalizedFileActionFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "MKD.exists", fileName, file));
            return;
        }

        // now create directory
        if (file.mkdir()) {
            session.write(LocalizedFileActionFtpReply.translate(session, request, context,
                    FtpReply.REPLY_257_PATHNAME_CREATED, "MKD", fileName, file));

            // write log message
            String userName = session.getUser().getName();
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

                    "MDTM", 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, "MDTM",
                    fileName));
            return;
        }

        // now print date
        fileName = file.getAbsolutePath();
        if (file.doesExist()) {
            String dateStr = DateUtils.getFtpDate(file.getLastModified());
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_213_FILE_STATUS, "MDTM", dateStr));
        } else {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "MDTM",
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

        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

Examples of org.apache.ftpserver.ftplet.FtpFile

                                        "RETR", null, 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(LocalizedDataTransferFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "RETR.missing", fileName, file));
                return;
            }
            fileName = file.getAbsolutePath();

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

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

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

Examples of org.apache.ftpserver.ftplet.FtpFile

    public void testSingleFile() {
        assertEquals("short\r\n", formater.format(TEST_FILE));
    }

    public void testSingleDir() {
        FtpFile dir = new MockFileObject() {
            @Override
            public boolean isDirectory() {
                return true;
            }
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

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

    public void testSingleDir() {
        FtpFile dir = new MockFileObject() {
            @Override
            public boolean isDirectory() {
                return true;
            }
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

    public void testSingleFile() {
        assertEquals(TEST_FILE_FORMAT, formater.format(TEST_FILE));
    }

    public void testSingleDir() {
        FtpFile dir = new MockFileObject() {
            @Override
            public int getLinkCount() {
                return 3;
            }
View Full Code Here

Examples of org.apache.ftpserver.ftplet.FtpFile

            // OK
        }
    }

    public void testFullName() {
        FtpFile fileObject = createFileObject(FILE2_PATH, USER);
        assertEquals("/dir1/file2", fileObject.getAbsolutePath());

        fileObject = createFileObject("/dir1/", USER);
        assertEquals("/dir1", fileObject.getAbsolutePath());

        fileObject = createFileObject("/dir1", USER);
        assertEquals("/dir1", fileObject.getAbsolutePath());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.