Examples of FTPSClient


Examples of org.apache.commons.net.ftp.FTPSClient

   
    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry jndi = super.createRegistry();

        jndi.bind("ftpsClient", new FTPSClient("SSL"));
        jndi.bind("ftpsClientIn", new FTPSClient("SSL"));
        return jndi;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

   
    /**
     * Create the FTPS client.
     */
    protected FTPClient createFtpClient() throws Exception {
        FTPSClient client = null;
       
        if (sslContextParameters != null) {
            SSLContext context = sslContextParameters.createSSLContext();

            client = new FTPSClient(getFtpsConfiguration().isImplicit(), context);
           
            // The FTPSClient tries to manage the following SSLSocket related configuration options
            // on its own based on internal configuration options.  FTPSClient does not lend itself
            // to subclassing for the purpose of overriding this behavior (private methods, fields, etc.).
            // As such, we create a socket (preconfigured by SSLContextParameters) from the context
            // we gave to FTPSClient and then setup FTPSClient to reuse the already configured configuration
            // from the socket for all future sockets it creates.  Not sexy and a little brittle, but it works.
            SSLSocket socket = (SSLSocket)context.getSocketFactory().createSocket();
            client.setEnabledCipherSuites(socket.getEnabledCipherSuites());
            client.setEnabledProtocols(socket.getEnabledProtocols());
            client.setNeedClientAuth(socket.getNeedClientAuth());
            client.setWantClientAuth(socket.getWantClientAuth());
            client.setEnabledSessionCreation(socket.getEnableSessionCreation());
        } else {
            client = new FTPSClient(getFtpsConfiguration().getSecurityProtocol(),
                                               getFtpsConfiguration().isImplicit());
           
            if (ftpClientKeyStoreParameters != null) {
                String type = (ftpClientKeyStoreParameters.containsKey("type"))
                        ? (String) ftpClientKeyStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientKeyStoreParameters.get("file");
                String password = (String) ftpClientKeyStoreParameters.get("password");
                String algorithm = (ftpClientKeyStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientKeyStoreParameters.get("algorithm")
                        : KeyManagerFactory.getDefaultAlgorithm();
                String keyPassword = (String) ftpClientKeyStoreParameters.get("keyPassword");
               
                KeyStore keyStore = KeyStore.getInstance(type);
                FileInputStream keyStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    keyStore.load(keyStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(keyStoreFileInputStream, "keyStore", log);
                }
   
                KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance(algorithm);
                keyMgrFactory.init(keyStore, keyPassword.toCharArray());
                client.setNeedClientAuth(true);
                client.setKeyManager(keyMgrFactory.getKeyManagers()[0]);
            }
   
            if (ftpClientTrustStoreParameters != null) {
                String type = (ftpClientTrustStoreParameters.containsKey("type"))
                        ? (String) ftpClientTrustStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientTrustStoreParameters.get("file");
                String password = (String) ftpClientTrustStoreParameters.get("password");
                String algorithm = (ftpClientTrustStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientTrustStoreParameters.get("algorithm")
                        : TrustManagerFactory.getDefaultAlgorithm();
                       
                KeyStore trustStore = KeyStore.getInstance(type);
                FileInputStream trustStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    trustStore.load(trustStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(trustStoreFileInputStream, "trustStore", log);
                }
   
                TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(algorithm);
                trustMgrFactory.init(trustStore);
               
                client.setTrustManager(trustMgrFactory.getTrustManagers()[0]);
            }
        }
       
        return client;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

    }

    @Override
    public RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
        // configure ftp client
        FTPSClient client = getFtpsClient();

        if (client == null) {
            // must use a new client if not explicit configured to use a custom client
            client = (FTPSClient) createFtpClient();
        }

        // set any endpoint configured timeouts
        if (getConfiguration().getConnectTimeout() > -1) {
            client.setConnectTimeout(getConfiguration().getConnectTimeout());
        }
        if (getConfiguration().getSoTimeout() > -1) {
            soTimeout = getConfiguration().getSoTimeout();
        }
        dataTimeout = getConfiguration().getTimeout();

        if (ftpClientParameters != null) {
            Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);
            // setting soTimeout has to be done later on FTPClient (after it has connected)
            Object timeout = localParameters.remove("soTimeout");
            if (timeout != null) {
                soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
            }
            // and we want to keep data timeout so we can log it later
            timeout = localParameters.remove("dataTimeout");
            if (timeout != null) {
                dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
            }
            setProperties(client, localParameters);
        }

        if (ftpClientConfigParameters != null) {
            // client config is optional so create a new one if we have parameter for it
            if (ftpClientConfig == null) {
                ftpClientConfig = new FTPClientConfig();
            }
            Map<String, Object> localConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
            setProperties(ftpClientConfig, localConfigParameters);
        }

        if (dataTimeout > 0) {
            client.setDataTimeout(dataTimeout);
        }

        if (log.isDebugEnabled()) {
            log.debug("Created FTPSClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}]: {}",
                    new Object[]{client.getConnectTimeout(), getSoTimeout(), dataTimeout, client});
        }

        FtpsOperations operations = new FtpsOperations(client, getFtpClientConfig());
        operations.setEndpoint(this);
        return operations;
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

   
    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry jndi = super.createRegistry();

        FTPSClient ftpsClient = new FTPSClient("SSL");

        jndi.bind("ftpsClient", ftpsClient);
        return jndi;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

   
    /**
     * Create the FTPS client.
     */
    protected FTPClient createFtpClient() throws Exception {
        FTPSClient client = null;
       
        if (sslContextParameters != null) {
            SSLContext context = sslContextParameters.createSSLContext();

            client = new FTPSClient(getFtpsConfiguration().isImplicit(), context);
           
            // The FTPSClient tries to manage the following SSLSocket related configuration options
            // on its own based on internal configuration options.  FTPSClient does not lend itself
            // to subclassing for the purpose of overriding this behavior (private methods, fields, etc.).
            // As such, we create a socket (preconfigured by SSLContextParameters) from the context
            // we gave to FTPSClient and then setup FTPSClient to reuse the already configured configuration
            // from the socket for all future sockets it creates.  Not sexy and a little brittle, but it works.
            SSLSocket socket = (SSLSocket)context.getSocketFactory().createSocket();
            client.setEnabledCipherSuites(socket.getEnabledCipherSuites());
            client.setEnabledProtocols(socket.getEnabledProtocols());
            client.setNeedClientAuth(socket.getNeedClientAuth());
            client.setWantClientAuth(socket.getWantClientAuth());
            client.setEnabledSessionCreation(socket.getEnableSessionCreation());
        } else {
            client = new FTPSClient(getFtpsConfiguration().getSecurityProtocol(),
                                               getFtpsConfiguration().isImplicit());
           
            if (ftpClientKeyStoreParameters != null) {
                String type = (ftpClientKeyStoreParameters.containsKey("type"))
                        ? (String) ftpClientKeyStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientKeyStoreParameters.get("file");
                String password = (String) ftpClientKeyStoreParameters.get("password");
                String algorithm = (ftpClientKeyStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientKeyStoreParameters.get("algorithm")
                        : KeyManagerFactory.getDefaultAlgorithm();
                String keyPassword = (String) ftpClientKeyStoreParameters.get("keyPassword");
               
                KeyStore keyStore = KeyStore.getInstance(type);
                FileInputStream keyStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    keyStore.load(keyStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(keyStoreFileInputStream, "keyStore", log);
                }
   
                KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance(algorithm);
                keyMgrFactory.init(keyStore, keyPassword.toCharArray());
                client.setNeedClientAuth(true);
                client.setKeyManager(keyMgrFactory.getKeyManagers()[0]);
            }
   
            if (ftpClientTrustStoreParameters != null) {
                String type = (ftpClientTrustStoreParameters.containsKey("type"))
                        ? (String) ftpClientTrustStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientTrustStoreParameters.get("file");
                String password = (String) ftpClientTrustStoreParameters.get("password");
                String algorithm = (ftpClientTrustStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientTrustStoreParameters.get("algorithm")
                        : TrustManagerFactory.getDefaultAlgorithm();
                       
                KeyStore trustStore = KeyStore.getInstance(type);
                FileInputStream trustStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    trustStore.load(trustStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(trustStoreFileInputStream, "trustStore", log);
                }
   
                TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(algorithm);
                trustMgrFactory.init(trustStore);
               
                client.setTrustManager(trustMgrFactory.getTrustManagers()[0]);
            }
        }
       
        return client;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

    }

    @Override
    public RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
        // configure ftp client
        FTPSClient client = getFtpsClient();

        if (client == null) {
            // must use a new client if not explicit configured to use a custom client
            client = (FTPSClient) createFtpClient();
        }

        // set any endpoint configured timeouts
        if (getConfiguration().getConnectTimeout() > -1) {
            client.setConnectTimeout(getConfiguration().getConnectTimeout());
        }
        if (getConfiguration().getSoTimeout() > -1) {
            soTimeout = getConfiguration().getSoTimeout();
        }
        dataTimeout = getConfiguration().getTimeout();

        if (ftpClientParameters != null) {
            // setting soTimeout has to be done later on FTPClient (after it has connected)
            Object timeout = ftpClientParameters.remove("soTimeout");
            if (timeout != null) {
                soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
            }
            // and we want to keep data timeout so we can log it later
            timeout = ftpClientParameters.remove("dataTimeout");
            if (timeout != null) {
                dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
            }
            IntrospectionSupport.setProperties(client, ftpClientParameters);
        }

        if (ftpClientConfigParameters != null) {
            // client config is optional so create a new one if we have parameter for it
            if (ftpClientConfig == null) {
                ftpClientConfig = new FTPClientConfig();
            }
            IntrospectionSupport.setProperties(ftpClientConfig, ftpClientConfigParameters);
        }

        if (dataTimeout > 0) {
            client.setDataTimeout(dataTimeout);
        }

        if (log.isDebugEnabled()) {
            log.debug("Created FTPSClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}]: {}",
                    new Object[]{client.getConnectTimeout(), getSoTimeout(), dataTimeout, client});
        }

        FtpsOperations operations = new FtpsOperations(client, getFtpClientConfig());
        operations.setEndpoint(this);
        return operations;
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

        final FTPClient ftp;
        if (protocol == null ) {
            ftp = new FTPClient();
        } else {
            FTPSClient ftps;
            if (protocol.equals("true")) {
                ftps = new FTPSClient(true);
            } else if (protocol.equals("false")) {
                ftps = new FTPSClient(false);
            } else {
                String prot[] = protocol.split(",");
                if (prot.length == 1) { // Just protocol
                    ftps = new FTPSClient(protocol);
                } else { // protocol,true|false
                    ftps = new FTPSClient(prot[0], Boolean.parseBoolean(prot[1]));
                }
            }
            ftp = ftps;
            if ("all".equals(trustmgr)) {
                ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
            } else if ("valid".equals(trustmgr)) {
                ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
            } else if ("none".equals(trustmgr)) {
                ftps.setTrustManager(null);
            }
        }

        if (printHash) {
            ftp.setCopyStreamListener(createListener());
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

   
    /**
     * Create the FTPS client.
     */
    protected FTPClient createFtpClient() throws Exception {
        FTPSClient client = null;
       
        if (sslContextParameters != null) {
            SSLContext context = sslContextParameters.createSSLContext();

            client = new FTPSClient(getFtpsConfiguration().isImplicit(), context);
           
            // The FTPSClient tries to manage the following SSLSocket related configuration options
            // on its own based on internal configuration options.  FTPSClient does not lend itself
            // to subclassing for the purpose of overriding this behavior (private methods, fields, etc.).
            // As such, we create a socket (preconfigured by SSLContextParameters) from the context
            // we gave to FTPSClient and then setup FTPSClient to reuse the already configured configuration
            // from the socket for all future sockets it creates.  Not sexy and a little brittle, but it works.
            SSLSocket socket = (SSLSocket)context.getSocketFactory().createSocket();
            client.setEnabledCipherSuites(socket.getEnabledCipherSuites());
            client.setEnabledProtocols(socket.getEnabledProtocols());
            client.setNeedClientAuth(socket.getNeedClientAuth());
            client.setWantClientAuth(socket.getWantClientAuth());
            client.setEnabledSessionCreation(socket.getEnableSessionCreation());
        } else {
            client = new FTPSClient(getFtpsConfiguration().getSecurityProtocol(),
                                               getFtpsConfiguration().isImplicit());
           
            if (ftpClientKeyStoreParameters != null) {
                String type = (ftpClientKeyStoreParameters.containsKey("type"))
                        ? (String) ftpClientKeyStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientKeyStoreParameters.get("file");
                String password = (String) ftpClientKeyStoreParameters.get("password");
                String algorithm = (ftpClientKeyStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientKeyStoreParameters.get("algorithm")
                        : KeyManagerFactory.getDefaultAlgorithm();
                String keyPassword = (String) ftpClientKeyStoreParameters.get("keyPassword");
               
                KeyStore keyStore = KeyStore.getInstance(type);
                FileInputStream keyStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    keyStore.load(keyStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(keyStoreFileInputStream, "keyStore", log);
                }
   
                KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance(algorithm);
                keyMgrFactory.init(keyStore, keyPassword.toCharArray());
                client.setNeedClientAuth(true);
                client.setKeyManager(keyMgrFactory.getKeyManagers()[0]);
            }
   
            if (ftpClientTrustStoreParameters != null) {
                String type = (ftpClientTrustStoreParameters.containsKey("type"))
                        ? (String) ftpClientTrustStoreParameters.get("type") : KeyStore.getDefaultType();
                String file = (String) ftpClientTrustStoreParameters.get("file");
                String password = (String) ftpClientTrustStoreParameters.get("password");
                String algorithm = (ftpClientTrustStoreParameters.containsKey("algorithm"))
                        ? (String) ftpClientTrustStoreParameters.get("algorithm")
                        : TrustManagerFactory.getDefaultAlgorithm();
                       
                KeyStore trustStore = KeyStore.getInstance(type);
                FileInputStream trustStoreFileInputStream = new FileInputStream(new File(file));
                try {
                    trustStore.load(trustStoreFileInputStream, password.toCharArray());
                } finally {
                    IOHelper.close(trustStoreFileInputStream, "trustStore", log);
                }
   
                TrustManagerFactory trustMgrFactory = TrustManagerFactory.getInstance(algorithm);
                trustMgrFactory.init(trustStore);
               
                client.setTrustManager(trustMgrFactory.getTrustManagers()[0]);
            }
        }
       
        return client;
    }
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

    }

    @Override
    public RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
        // configure ftp client
        FTPSClient client = getFtpsClient();

        if (client == null) {
            // must use a new client if not explicit configured to use a custom client
            client = (FTPSClient) createFtpClient();
        }

        // set any endpoint configured timeouts
        if (getConfiguration().getConnectTimeout() > -1) {
            client.setConnectTimeout(getConfiguration().getConnectTimeout());
        }
        if (getConfiguration().getSoTimeout() > -1) {
            soTimeout = getConfiguration().getSoTimeout();
        }
        dataTimeout = getConfiguration().getTimeout();

        if (ftpClientParameters != null) {
            Map<String, Object> localParameters = new HashMap<String, Object>(ftpClientParameters);
            // setting soTimeout has to be done later on FTPClient (after it has connected)
            Object timeout = localParameters.remove("soTimeout");
            if (timeout != null) {
                soTimeout = getCamelContext().getTypeConverter().convertTo(int.class, timeout);
            }
            // and we want to keep data timeout so we can log it later
            timeout = localParameters.remove("dataTimeout");
            if (timeout != null) {
                dataTimeout = getCamelContext().getTypeConverter().convertTo(int.class, dataTimeout);
            }
            setProperties(client, localParameters);
        }

        if (ftpClientConfigParameters != null) {
            // client config is optional so create a new one if we have parameter for it
            if (ftpClientConfig == null) {
                ftpClientConfig = new FTPClientConfig();
            }
            Map<String, Object> localConfigParameters = new HashMap<String, Object>(ftpClientConfigParameters);
            setProperties(ftpClientConfig, localConfigParameters);
        }

        if (dataTimeout > 0) {
            client.setDataTimeout(dataTimeout);
        }

        if (log.isDebugEnabled()) {
            log.debug("Created FTPSClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}]: {}",
                    new Object[]{client.getConnectTimeout(), getSoTimeout(), dataTimeout, client});
        }

        FtpsOperations operations = new FtpsOperations(client, getFtpClientConfig());
        operations.setEndpoint(this);
        return operations;
View Full Code Here

Examples of org.apache.commons.net.ftp.FTPSClient

            }
            else {
                ftp = new FTPClient();
            }
        } else {
            FTPSClient ftps;
            if (protocol.equals("true")) {
                ftps = new FTPSClient(true);
            } else if (protocol.equals("false")) {
                ftps = new FTPSClient(false);
            } else {
                String prot[] = protocol.split(",");
                if (prot.length == 1) { // Just protocol
                    ftps = new FTPSClient(protocol);
                } else { // protocol,true|false
                    ftps = new FTPSClient(prot[0], Boolean.parseBoolean(prot[1]));
                }
            }
            ftp = ftps;
            if ("all".equals(trustmgr)) {
                ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
            } else if ("valid".equals(trustmgr)) {
                ftps.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
            } else if ("none".equals(trustmgr)) {
                ftps.setTrustManager(null);
            }
        }

        if (printHash) {
            ftp.setCopyStreamListener(createListener());
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.