Package org.apache.ftpserver.ftplet

Examples of org.apache.ftpserver.ftplet.FileObject


            session.closeOnFlush().awaitUninterruptibly(10000);
            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();
            LOG.info("Directory create : " + userName + " - " + fileName);
View Full Code Here


            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "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", fileName));
        }
View Full Code Here

        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

                session.closeOnFlush().awaitUninterruptibly(10000);
                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;
            }

            // 24-10-2007 - added check if PORT or PASV is issued, see https://issues.apache.org/jira/browse/FTPSERVER-110
View Full Code Here

            session.closeOnFlush().awaitUninterruptibly(10000);
            return;
        }

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

        // check file
        fileName = file.getFullName();

        if( !file.hasDeletePermission() ) {
            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "DELE.permission", fileName));
            return;
        }
       
        // now delete
        if(file.delete()) {
          session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_250_REQUESTED_FILE_ACTION_OKAY, "DELE", fileName));
           
            // log message
            String userName = session.getUser().getName();
           
View Full Code Here

            }
           
            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

     * 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

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

    public void testSingleDir() {
        FileObject 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() {
        FileObject dir = new MockFileObject() {
            public boolean isDirectory() {
                return true;
            }

            public boolean isFile() {
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.