Package org.apache.ftpserver.ftplet

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() {
            public int getLinkCount() {
                return 3;
            }

            public boolean isDirectory() {
View Full Code Here


    public void testSingleFile() {
        assertEquals("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

                    return;
                }
            }

            // get filename
            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,
                        "STOR.invalid", fileName));
                return;
            }
            fileName = file.getAbsolutePath();

            // get permission
            if (!file.isWritable()) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "STOR.permission", fileName));
                return;
            }

            // get data connection
            session.write(
                    LocalizedFtpReply.translate(session, request, context,
                            FtpReply.REPLY_150_FILE_STATUS_OKAY, "STOR",
                            fileName)).awaitUninterruptibly(10000);

            DataConnection dataConnection;
            try {
                dataConnection = session.getDataConnection().openConnection();
            } catch (Exception e) {
                LOG.debug("Exception getting the input data stream", e);
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "STOR",
                        fileName));
                return;
            }

            // transfer data
            boolean failure = false;
            OutputStream outStream = null;
            try {
                outStream = file.createOutputStream(skipLen);
                long transSz = dataConnection.transferFromClient(session.getFtpletSession(), outStream);

                // attempt to close the output stream so that errors in
                // closing it will return an error to the client (FTPSERVER-119)
                if(outStream != null) {
View Full Code Here

                    return;
                }
            }

            // get filenames
            FtpFile file = null;
            try {
                file = session.getFileSystemView().getFile(fileName);
            } catch (Exception e) {
                LOG.debug("File system threw exception", e);
            }
            if (file == null) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "APPE.invalid", fileName));
                return;
            }
            fileName = file.getAbsolutePath();

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

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

            // get data connection
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_150_FILE_STATUS_OKAY, "APPE", fileName));

            DataConnection dataConnection;
            try {
                dataConnection = session.getDataConnection().openConnection();
            } catch (Exception e) {
                LOG.debug("Exception when getting data input stream", e);
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "APPE",
                        fileName));
                return;
            }

            // get data from client
            boolean failure = false;
            OutputStream os = null;
            try {

                // find offset
                long offset = 0L;
                if (file.doesExist()) {
                    offset = file.getSize();
                }

                // open streams
                os = file.createOutputStream(offset);

                // transfer data
                long transSz = dataConnection.transferFromClient(session.getFtpletSession(), os);

                // attempt to close the output stream so that errors in
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

                                        "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

                    return;
                }
            }

            // get filenames
            FtpFile file = null;
            try {
                file = session.getFileSystemView().getFile(fileName);
            } catch (Exception e) {
                LOG.debug("File system threw exception", e);
            }
            if (file == null) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                        "APPE.invalid", fileName));
                return;
            }
            fileName = file.getAbsolutePath();

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

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

            // get data connection
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_150_FILE_STATUS_OKAY, "APPE", fileName));

            DataConnection dataConnection;
            try {
                dataConnection = session.getDataConnection().openConnection();
            } catch (Exception e) {
                LOG.debug("Exception when getting data input stream", e);
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_425_CANT_OPEN_DATA_CONNECTION, "APPE",
                        fileName));
                return;
            }

            // get data from client
            boolean failure = false;
            OutputStream os = null;
            try {

                // find offset
                long offset = 0L;
                if (file.doesExist()) {
                    offset = file.getSize();
                }

                // open streams
                os = file.createOutputStream(offset);

                // transfer data
                long transSz = dataConnection.transferFromClient(session.getFtpletSession(), os);

                // attempt to close the output stream so that errors in
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;
        }

        fileName = file.getAbsolutePath();

        // first let's make sure the path is a directory
        if (!file.isDirectory()) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "RMD.invalid", fileName));
            return;
        }

        // then make sure that the client did not request the deletion of
        // current working directory.  
        FtpFile cwd = session.getFileSystemView().getWorkingDirectory();
        if(file.equals(cwd)) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "RMD.busy",
                fileName));
            return;
View Full Code Here

                    "RNFR", null));
            return;
        }

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

        // check file
        if (renFr == null) {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "RNFR",
                    fileName));
        } else {
            session.setRenameFrom(renFr);
            fileName = renFr.getAbsolutePath();
            session
                    .write(LocalizedFtpReply
                            .translate(
                                    session,
                                    request,
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.