Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.FileObject


        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < fileNames.length; i++) {
            String fileName = fileNames[i].trim();

            // get file object
            FileObject file = null;

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

            if (file == null) {
                session
                        .write(FtpReplyUtil
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_504_COMMAND_NOT_IMPLEMENTED_FOR_THAT_PARAMETER,
                                        "MD5.invalid", fileName));
                return;
            }

            // check file
            if (!file.isFile()) {
                session
                        .write(FtpReplyUtil
                                .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


                                        "RETR", 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,
                        "RETR.missing", fileName));
                return;
            }
            fileName = file.getFullName();

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

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

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

                    return;
                }
            }

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

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

            // get data connection
            session.write(
                    FtpReplyUtil.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(FtpReplyUtil.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(outStream);

                // log message
                String userName = session.getUser().getName();
                LOG.info("File upload : " + userName + " - " + fileName);
View Full Code Here

                    "SIZE", 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,
                    "SIZE.missing", fileName));
            return;
        }

        // print file size
        fileName = file.getFullName();
        if (!file.doesExist()) {
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "SIZE.missing", fileName));
        } else if (!file.isFile()) {
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "SIZE.invalid", fileName));
        } else {
            String fileLen = String.valueOf(file.getSize());
            session.write(FtpReplyUtil.translate(session, request, context,
                    FtpReply.REPLY_213_FILE_STATUS, "SIZE", fileLen));
        }
    }
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.