Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.FtpFile


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

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

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

        // now create directory
        if (file.mkdir()) {
            session.write(LocalizedFtpReply.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
        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

        StringBuffer sb = new StringBuffer();
        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

                                        "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);

                // log message
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);

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

            if (f.getProperty(AbstractFile.parent) != null) {
              continue;
            }

            FtpFile ftpFile = new StructrFtpFolder(f);
            logger.log(Level.INFO, "Folder found: {0}", ftpFile.getAbsolutePath());

            ftpFiles.add(ftpFile);

          }

          Result<File> files = app.nodeQuery(File.class).getResult();
          logger.log(Level.INFO, "{0} files found", files.size());

          for (File f : files.getResults()) {

            if (f.getProperty(AbstractFile.parent) != null) {
              continue;
            }

            logger.log(Level.FINEST, "Structr file found: {0}", f);

            FtpFile ftpFile = new StructrFtpFile(f);
            logger.log(Level.FINE, "File found: {0}", ftpFile.getAbsolutePath());

            ftpFiles.add(ftpFile);

          }

          Result<Page> pages = app.nodeQuery(Page.class).getResult();
          logger.log(Level.INFO, "{0} pages found", pages.size());

          for (Page p : pages.getResults()) {

            logger.log(Level.FINEST, "Structr page found: {0}", p);

            ftpFiles.add(p);

          }

          return ftpFiles;

        } catch (FrameworkException ex) {
          logger.log(Level.SEVERE, null, ex);
        }

      }

      List<Folder> folders = ((Folder) structrFile).getProperty(Folder.folders);

      for (Folder f : folders) {

        FtpFile ftpFile = new StructrFtpFolder(f);
        logger.log(Level.INFO, "Subfolder found: {0}", ftpFile.getAbsolutePath());

        ftpFiles.add(ftpFile);
      }

      List<File> files = ((Folder) structrFile).getProperty(Folder.files);

      for (File f : files) {

        FtpFile ftpFile = new StructrFtpFile(f);
        logger.log(Level.INFO, "File found: {0}", ftpFile.getAbsolutePath());

        ftpFiles.add(ftpFile);
      }

      return ftpFiles;
View Full Code Here

    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

     * Get the file list. Files will be listed in alphabetlical order.
     */
    private List<FtpFile> listFiles(FileSystemView fileSystemView, String file) {
        List<FtpFile> files = null;
        try {
            FtpFile virtualFile = fileSystemView.getFile(file);
            if (virtualFile.isFile()) {
                files = new ArrayList<FtpFile>();
                files.add(virtualFile);
            } else {
                files = virtualFile.listFiles();
            }
        } catch (FtpException ex) {
        }
        return files;
    }
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.