Search in sources :

Example 1 with FTPClientConfig

use of org.apache.commons.net.ftp.FTPClientConfig in project camel by apache.

the class FtpEndpoint method createRemoteFileOperations.

public RemoteFileOperations<FTPFile> createRemoteFileOperations() throws Exception {
    // configure ftp client
    FTPClient client = ftpClient;
    if (client == null) {
        // must use a new client if not explicit configured to use a custom client
        client = createFtpClient();
    }
    // use configured buffer size which is larger and therefore faster (as the default is no buffer)
    if (getConfiguration().getReceiveBufferSize() > 0) {
        client.setBufferSize(getConfiguration().getReceiveBufferSize());
    }
    // set any endpoint configured timeouts
    if (getConfiguration().getConnectTimeout() > -1) {
        client.setConnectTimeout(getConfiguration().getConnectTimeout());
    }
    if (getConfiguration().getSoTimeout() > -1) {
        soTimeout = getConfiguration().getSoTimeout();
    }
    dataTimeout = getConfiguration().getTimeout();
    if (getConfiguration().getActivePortRange() != null) {
        // parse it as min-max
        String[] parts = getConfiguration().getActivePortRange().split("-");
        if (parts.length != 2) {
            throw new IllegalArgumentException("The option activePortRange should have syntax: min-max");
        }
        int min = getCamelContext().getTypeConverter().mandatoryConvertTo(int.class, parts[0]);
        int max = getCamelContext().getTypeConverter().mandatoryConvertTo(int.class, parts[1]);
        log.debug("Using active port range: {}-{}", min, max);
        client.setActivePortRange(min, max);
    }
    // then lookup ftp client parameters and set those
    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 FTPClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}, bufferSize: {}" + ", receiveDataSocketBufferSize: {}, sendDataSocketBufferSize: {}]: {}", new Object[] { client.getConnectTimeout(), getSoTimeout(), dataTimeout, client.getBufferSize(), client.getReceiveDataSocketBufferSize(), client.getSendDataSocketBufferSize(), client });
    }
    FtpOperations operations = new FtpOperations(client, getFtpClientConfig());
    operations.setEndpoint(this);
    return operations;
}
Also used : HashMap(java.util.HashMap) FTPClientConfig(org.apache.commons.net.ftp.FTPClientConfig) FTPClient(org.apache.commons.net.ftp.FTPClient) UriEndpoint(org.apache.camel.spi.UriEndpoint)

Example 2 with FTPClientConfig

use of org.apache.commons.net.ftp.FTPClientConfig in project camel by apache.

the class FtpsEndpoint method createRemoteFileOperations.

@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();
    }
    // use configured buffer size which is larger and therefore faster (as the default is no buffer)
    if (getConfiguration().getReceiveBufferSize() > 0) {
        client.setBufferSize(getConfiguration().getReceiveBufferSize());
    }
    // 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 FTPClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}, bufferSize: {}" + ", receiveDataSocketBufferSize: {}, sendDataSocketBufferSize: {}]: {}", new Object[] { client.getConnectTimeout(), getSoTimeout(), dataTimeout, client.getBufferSize(), client.getReceiveDataSocketBufferSize(), client.getSendDataSocketBufferSize(), client });
    }
    FtpsOperations operations = new FtpsOperations(client, getFtpClientConfig());
    operations.setEndpoint(this);
    return operations;
}
Also used : HashMap(java.util.HashMap) FTPClientConfig(org.apache.commons.net.ftp.FTPClientConfig) FTPSClient(org.apache.commons.net.ftp.FTPSClient)

Example 3 with FTPClientConfig

use of org.apache.commons.net.ftp.FTPClientConfig in project camel by apache.

the class FtpConsumerUsingFTPClientConfigTest method createConfig.

private FTPClientConfig createConfig() {
    FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
    config.setServerTimeZoneId("Europe/Paris");
    return config;
}
Also used : FTPClientConfig(org.apache.commons.net.ftp.FTPClientConfig)

Example 4 with FTPClientConfig

use of org.apache.commons.net.ftp.FTPClientConfig in project camel by apache.

the class FromFtpClientConfigRefTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry jndi = super.createRegistry();
    FTPClientConfig config = new FTPClientConfig();
    config.setServerLanguageCode("fr");
    config.setLenientFutureDates(true);
    jndi.bind("myConfig", config);
    return jndi;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) FTPClientConfig(org.apache.commons.net.ftp.FTPClientConfig)

Aggregations

FTPClientConfig (org.apache.commons.net.ftp.FTPClientConfig)4 HashMap (java.util.HashMap)2 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 UriEndpoint (org.apache.camel.spi.UriEndpoint)1 FTPClient (org.apache.commons.net.ftp.FTPClient)1 FTPSClient (org.apache.commons.net.ftp.FTPSClient)1