Examples of ServerFtpStatistics


Examples of org.apache.ftpserver.impl.ServerFtpStatistics

                long transSz = dataConnection.transferFromClient(session.getFtpletSession(), outStream);

                LOG.info("File uploaded {}", fileName);

                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
                        .getFtpStatistics();
                ftpStat.setUpload(session, file, transSz);
               
                // attempt to close the output stream so that errors in
                // closing it will return an error to the client (FTPSERVER-119)
                if(outStream != null) {
                    outStream.close();
View Full Code Here

Examples of org.apache.ftpserver.impl.ServerFtpStatistics

            final FtpServerContext context, final FtpRequest request)
            throws IOException, FtpException {

        boolean success = false;

        ServerFtpStatistics stat = (ServerFtpStatistics) context
                .getFtpStatistics();
        try {

            // reset state variables
            session.resetState();

            // argument check
            String password = request.getArgument();


            // check user name
            String userName = session.getUserArgument();

            if (userName == null && session.getUser() == null) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PASS",
                        null));
                return;
            }

            // already logged-in
            if (session.isLoggedIn()) {
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_202_COMMAND_NOT_IMPLEMENTED, "PASS",
                        null));
                return;
            }

            // anonymous login limit check

            boolean anonymous = userName != null
                    && userName.equals("anonymous");
            if (anonymous) {
                int currAnonLogin = stat.getCurrentAnonymousLoginNumber();
                int maxAnonLogin = context.getConnectionConfig()
                        .getMaxAnonymousLogins();
                if (currAnonLogin >= maxAnonLogin) {
                    session
                            .write(LocalizedFtpReply
                                    .translate(
                                            session,
                                            request,
                                            context,
                                            FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
                                            "PASS.anonymous", null));
                    return;
                }
            }

            // login limit check
            int currLogin = stat.getCurrentLoginNumber();
            int maxLogin = context.getConnectionConfig().getMaxLogins();
            if (maxLogin != 0 && currLogin >= maxLogin) {
                session
                        .write(LocalizedFtpReply
                                .translate(
                                        session,
                                        request,
                                        context,
                                        FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION,
                                        "PASS.login", null));
                return;
            }

            // authenticate user
            UserManager userManager = context.getUserManager();
            User authenticatedUser = null;
            try {
                UserMetadata userMetadata = new UserMetadata();

                if (session.getRemoteAddress() instanceof InetSocketAddress) {
                    userMetadata.setInetAddress(((InetSocketAddress) session
                            .getRemoteAddress()).getAddress());
                }
                userMetadata.setCertificateChain(session
                        .getClientCertificates());

                Authentication auth;
                if (anonymous) {
                    auth = new AnonymousAuthentication(userMetadata);
                } else {
                    auth = new UsernamePasswordAuthentication(userName,
                            password, userMetadata);
                }

                authenticatedUser = userManager.authenticate(auth);
            } catch (AuthenticationFailedException e) {
                authenticatedUser = null;
                LOG.warn("User failed to log in");
            } catch (Exception e) {
                authenticatedUser = null;
                LOG.warn("PASS.execute()", e);
            }

            // first save old values so that we can reset them if Ftplets
            // tell us to fail
            User oldUser = session.getUser();
            String oldUserArgument = session.getUserArgument();
            int oldMaxIdleTime = session.getMaxIdleTime();

            if (authenticatedUser != null) {
                session.setUser(authenticatedUser);
                session.setUserArgument(null);
                session.setMaxIdleTime(authenticatedUser.getMaxIdleTime());
                success = true;
            } else {
                session.setUser(null);
            }

            if (!success) {
                // reset due to failure
                session.setUser(oldUser);
                session.setUserArgument(oldUserArgument);
                session.setMaxIdleTime(oldMaxIdleTime);

                delayAfterLoginFailure(context.getConnectionConfig()
                        .getLoginFailureDelay());

                LOG.warn("Login failure - " + userName);
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_530_NOT_LOGGED_IN, "PASS", userName));
                stat.setLoginFail(session);

                session.increaseFailedLogins();

                // kick the user if the max number of failed logins is reached
                int maxAllowedLoginFailues = context.getConnectionConfig()
                        .getMaxLoginFailures();
                if (maxAllowedLoginFailues != 0
                        && session.getFailedLogins() >= maxAllowedLoginFailues) {
                    session.close(false).awaitUninterruptibly(10000);
                }

                return;
            }

            // update different objects
            FileSystemFactory fmanager = context.getFileSystemManager();
            FileSystemView fsview = fmanager
                    .createFileSystemView(authenticatedUser);
            session.setLogin(fsview);
            stat.setLogin(session);

            // everything is fine - send login ok message
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_230_USER_LOGGED_IN, "PASS", userName));
            if (anonymous) {
View Full Code Here

Examples of org.apache.ftpserver.impl.ServerFtpStatistics

            // write log message
            String userName = session.getUser().getName();
            LOG.info("Directory create : " + userName + " - " + fileName);

            // notify statistics object
            ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
                    .getFtpStatistics();
            ftpStat.setMkdir(session, file);

        } else {
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN, "MKD",
                    fileName));
View Full Code Here

Examples of org.apache.ftpserver.impl.ServerFtpStatistics

                long transSz = dataConnection.transferToClient(session.getFtpletSession(), is);

                LOG.info("File downloaded {}", fileName);

                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
                        .getFtpStatistics();
                if (ftpStat != null) {
                    ftpStat.setDownload(session, file, transSz);
                }
               
                // attempt to close the input stream so that errors in
                // closing it will return an error to the client (FTPSERVER-119)
                if(is != null) {
View Full Code Here

Examples of org.apache.ftpserver.impl.ServerFtpStatistics

                String userName = session.getUser().getName();

                LOG.info("File upload : " + userName + " - " + fileName);

                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
                        .getFtpStatistics();
                ftpStat.setUpload(session, file, transSz);
            } catch (SocketException e) {
                LOG.debug("SocketException during file upload", e);
                failure = true;
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED,
View Full Code Here

Examples of org.apache.ftpserver.impl.ServerFtpStatistics

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

                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics) context
                        .getFtpStatistics();
                ftpStat.setUpload(session, file, transSz);
            } catch (SocketException ex) {
                LOG.debug("Socket exception during data transfer", ex);
                failure = true;
                session.write(LocalizedFtpReply.translate(session, request, context,
                        FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED,
View Full Code Here

Examples of org.apache.ftpserver.interfaces.ServerFtpStatistics

                // log message
                String userName = session.getUser().getName();
                LOG.info("File upload : " + userName + " - " + fileName);
               
                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
                ftpStat.setUpload(session, file, transSz);
            }
            catch(SocketException ex) {
                LOG.debug("Socket exception during data transfer", ex);
                failure = true;
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "STOR", fileName));
View Full Code Here

Examples of org.apache.ftpserver.interfaces.ServerFtpStatistics

            final FtpServerContext context,
            final FtpRequest request) throws IOException, FtpException {
   
        boolean success = false;
       
        ServerFtpStatistics stat = (ServerFtpStatistics)context.getFtpStatistics();
        try {
           
            // reset state variables
            session.resetState();
           
            // argument check
            String password = request.getArgument();
            if(password == null) {
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PASS", null));
                return;
            }
           
            // check user name
            String userName = session.getUserArgument();

            if(userName == null && session.getUser() == null) {
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_503_BAD_SEQUENCE_OF_COMMANDS, "PASS", null));
                return;
            }
           
            // already logged-in
            if(session.isLoggedIn()) {
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_202_COMMAND_NOT_IMPLEMENTED, "PASS", null));
                return;
            }
           
            // anonymous login limit check
           
            boolean anonymous = userName != null && userName.equals("anonymous");
            if(anonymous) {
              int currAnonLogin = stat.getCurrentAnonymousLoginNumber();
              int maxAnonLogin = context.getConnectionConfig().getMaxAnonymousLogins();
              if( currAnonLogin >= maxAnonLogin ) {
                  session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "PASS.anonymous", null));
                  return;
              }
            }
             
            // login limit check
            int currLogin = stat.getCurrentLoginNumber();
            int maxLogin = context.getConnectionConfig().getMaxLogins();
            if(maxLogin != 0 && currLogin >= maxLogin) {
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_421_SERVICE_NOT_AVAILABLE_CLOSING_CONTROL_CONNECTION, "PASS.login", null));
                return;
            }
           
            // authenticate user
            UserManager userManager = context.getUserManager();
            User authenticatedUser = null;
            try {
                UserMetadata userMetadata = new UserMetadata();
               
                if(session.getRemoteAddress() instanceof InetSocketAddress) {
                  userMetadata.setInetAddress(((InetSocketAddress)session.getRemoteAddress()).getAddress());
                }
                userMetadata.setCertificateChain(session.getClientCertificates());
               
                Authentication auth;
                if(anonymous) {
                    auth = new AnonymousAuthentication(userMetadata);
                }
                else {
                    auth = new UsernamePasswordAuthentication(userName, password, userMetadata);
                }
                authenticatedUser = userManager.authenticate(auth);
            } catch(AuthenticationFailedException e) {
                authenticatedUser = null;
                LOG.warn("User failed to log in");               
            }
            catch(Exception e) {
                authenticatedUser = null;
                LOG.warn("PASS.execute()", e);
            }

            // set the user so that the Ftplets will be able to verify it
           
            // first save old values so that we can reset them if Ftplets
            // tell us to fail
            User oldUser = session.getUser();
            String oldUserArgument = session.getUserArgument();
            int oldMaxIdleTime = session.getMaxIdleTime();

            if(authenticatedUser != null) {
                session.setUser(authenticatedUser);
                session.setUserArgument(null);
                session.setMaxIdleTime(authenticatedUser.getMaxIdleTime());
                success = true;
            } else {
                session.setUser(null);
            }
           
            // call Ftplet.onLogin() method
            Ftplet ftpletContainer = context.getFtpletContainer();
            if(ftpletContainer != null) {
                FtpletEnum ftpletRet;
                try{
                    ftpletRet = ftpletContainer.onLogin(session.getFtpletSession(), request);
                } catch(Exception e) {
                    LOG.debug("Ftplet container threw exception", e);
                    ftpletRet = FtpletEnum.RET_DISCONNECT;
                }
                if(ftpletRet == FtpletEnum.RET_DISCONNECT) {
                    session.closeOnFlush().awaitUninterruptibly(10000);
                    return;
                } else if(ftpletRet == FtpletEnum.RET_SKIP) {
                    success = false;
                }
            }
           
            if(!success) {
                // reset due to failure
                session.setUser(oldUser);
                session.setUserArgument(oldUserArgument);
                session.setMaxIdleTime(oldMaxIdleTime);

                delayAfterLoginFailure(context.getConnectionConfig().getLoginFailureDelay());
               
                LOG.warn("Login failure - " + userName);
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_530_NOT_LOGGED_IN, "PASS", userName));
                stat.setLoginFail(session);

                session.increaseFailedLogins();

                // kick the user if the max number of failed logins is reached
                int maxAllowedLoginFailues = context.getConnectionConfig().getMaxLoginFailures();
                if(maxAllowedLoginFailues != 0 &&
                        session.getFailedLogins() >= maxAllowedLoginFailues) {
                    session.closeOnFlush().awaitUninterruptibly(10000);
                }
               
                return;
            }
           
            // update different objects
            FileSystemManager fmanager = context.getFileSystemManager();
            FileSystemView fsview = fmanager.createFileSystemView(authenticatedUser);
            session.setLogin(fsview);
            stat.setLogin(session);

            // everything is fine - send login ok message
            session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_230_USER_LOGGED_IN, "PASS", userName));
            if(anonymous) {
                LOG.info("Anonymous login success - " + password);
View Full Code Here

Examples of org.apache.ftpserver.interfaces.ServerFtpStatistics

                String userName = session.getUser().getName();

                LOG.info("File upload : " + userName + " - " + fileName);
               
                // notify the statistics component
                ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
                ftpStat.setUpload(session, file, transSz);
            }
            catch(SocketException e) {
                LOG.debug("SocketException during file upload", e);
                failure = true;
                session.write(FtpReplyUtil.translate(session, request, context, FtpReply.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED, "APPE", fileName));
View Full Code Here

Examples of org.apache.ftpserver.interfaces.ServerFtpStatistics

            // write log message
            String userName = session.getUser().getName();
            LOG.info("Directory remove : " + userName + " - " + fileName);
           
            // notify statistics object
            ServerFtpStatistics ftpStat = (ServerFtpStatistics)context.getFtpStatistics();
            ftpStat.setRmdir(session, file);
           
            // call Ftplet.onRmdirEnd() method
            try{
                ftpletRet = ftpletContainer.onRmdirEnd(session.getFtpletSession(), request);
            } catch(Exception e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.