Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.FileObject


                    "RMD", null));
            return;
        }

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

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

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

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

            // write log message
View Full Code Here


                    "RNFR", null));
            return;
        }

        // get filename
        FileObject renFr = null;
        try {
            renFr = session.getFileSystemView().getFileObject(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting file object", ex);
        }

        // check file
        if (renFr == null) {
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "RNFR",
                    fileName));
        } else {
            session.setRenameFrom(renFr);
            fileName = renFr.getFullName();
            session
                    .write(FtpReplyUtil
                            .translate(
                                    session,
                                    request,
View Full Code Here

                                        "RNTO", null));
                return;
            }

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

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

            // check permission
            if (!toFile.hasWritePermission()) {
                session
                        .write(FtpReplyUtil
                                .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(FtpReplyUtil
                                .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(FtpReplyUtil.translate(session, request, context,
                        FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "RNTO",
                        toFileStr));

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

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

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

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

            public boolean isFile() {
View Full Code Here

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

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

            public boolean isFile() {
View Full Code Here

     * Get the file list. Files will be listed in alphabetlical order.
     */
    private FileObject[] listFiles(FileSystemView fileSystemView, String file) {
        FileObject[] files = null;
        try {
            FileObject virtualFile = fileSystemView.getFileObject(file);
            if (virtualFile.isFile()) {
                files = new FileObject[] { virtualFile };
            } else {
                files = virtualFile.listFiles();
            }
        } catch (FtpException ex) {
        }
        return files;
    }
View Full Code Here

            session.resetState();

            String pathName = request.getArgument();

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

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

                    "MKD", null));
            return;
        }

        // get file object
        FileObject file = null;
        try {
            file = session.getFileSystemView().getFileObject(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting file object", ex);
        }
        if (file == null) {
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "MKD.invalid", fileName));
            return;
        }

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

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

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

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

                    "MDTM", null));
            return;
        }

        // get file object
        FileObject file = null;
        try {
            file = session.getFileSystemView().getFileObject(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting file object", ex);
        }
        if (file == null) {
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "MDTM",
                    fileName));
            return;
        }

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

TOP

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

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.