Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.camel.component.file.remote;
 
 import java.util.Map;
 
FTP endpoint
 
 public class FtpEndpoint<T extends FTPFileextends RemoteFileEndpoint<FTPFile> {
 
     protected FTPClient ftpClient;
     protected FTPClientConfig ftpClientConfig;
     protected Map<StringObjectftpClientParameters;
     protected Map<StringObjectftpClientConfigParameters;
     protected int soTimeout;
     protected int dataTimeout;
 
     public FtpEndpoint() {
     }
 
     public FtpEndpoint(String uriRemoteFileComponent<FTPFilecomponentRemoteFileConfiguration configuration) {
         super(uricomponentconfiguration);
     }
 
     @Override
     public String getScheme() {
         return "ftp";
     }
 
     @Override
     protected RemoteFileConsumer<FTPFilebuildConsumer(Processor processor) {
         try {
             return new FtpConsumer(thisprocessorcreateRemoteFileOperations());
         } catch (Exception e) {
             throw new FailedToCreateConsumerException(thise);
         }
     }
 
     protected GenericFileProducer<FTPFilebuildProducer() {
         try {
             return new RemoteFileProducer<FTPFile>(thiscreateRemoteFileOperations());
         } catch (Exception e) {
             throw new FailedToCreateProducerException(thise);
         }
     }
     
         // configure ftp client
         FTPClient client = ;
         
         if (client == null) {
             // must use a new client if not explicit configured to use a custom client
             client = createFtpClient();
         }
 
         // set any endpoint configured timeouts
         if (getConfiguration().getConnectTimeout() > -1) {
             client.setConnectTimeout(getConfiguration().getConnectTimeout());
         }
         if (getConfiguration().getSoTimeout() > -1) {
              = getConfiguration().getSoTimeout();
         }
          = getConfiguration().getTimeout();
 
         // then lookup ftp client parameters and set those
         if ( != null) {
             // setting soTimeout has to be done later on FTPClient (after it has connected)
             Object timeout = .remove("soTimeout");
             if (timeout != null) {
                  = getCamelContext().getTypeConverter().convertTo(int.classtimeout);
             }
             // and we want to keep data timeout so we can log it later
             timeout = .remove("dataTimeout");
            if (timeout != null) {
                 = getCamelContext().getTypeConverter().convertTo(int.class);
            }
            IntrospectionSupport.setProperties(client);
        }
        
        if ( != null) {
            // client config is optional so create a new one if we have parameter for it
            if ( == null) {
                 = new FTPClientConfig();
            }
            IntrospectionSupport.setProperties();
        }
        if ( > 0) {
            client.setDataTimeout();
        }
        if (.isDebugEnabled()) {
            .debug("Created FTPClient [connectTimeout: {}, soTimeout: {}, dataTimeout: {}]: {}"
                    new Object[]{client.getConnectTimeout(), getSoTimeout(), client});
        }
        FtpOperations operations = new FtpOperations(clientgetFtpClientConfig());
        operations.setEndpoint(this);
        return operations;
    }
    protected FTPClient createFtpClient() throws Exception {
        return new FTPClient();
    }
    @Override
        if ( == null) {
             = new FtpConfiguration();
        }
        return (FtpConfiguration);
    }
    @Override
    public void setConfiguration(GenericFileConfiguration configuration) {
        setConfiguration((FtpConfiguration)configuration);
    }
    public void setConfiguration(FtpConfiguration configuration) {
        if (configuration == null) {
            throw new IllegalArgumentException("FtpConfiguration expected");
        }
        this. = configuration;
    }
    public FTPClient getFtpClient() {
        return ;
    }
    public void setFtpClient(FTPClient ftpClient) {
        this. = ftpClient;
    }
        return ;
    }
    public void setFtpClientConfig(FTPClientConfig ftpClientConfig) {
        this. = ftpClientConfig;
    }

    
Used by FtpComponent to provide additional parameters for the FTPClient
    void setFtpClientParameters(Map<StringObjectftpClientParameters) {
        this. = ftpClientParameters;
    }

    
Used by FtpComponent to provide additional parameters for the FTPClientConfig
    void setFtpClientConfigParameters(Map<StringObjectftpClientConfigParameters) {
        this. = ftpClientConfigParameters;
    }
    public int getSoTimeout() {
        return ;
    }

    
Sets the soTimeout option.

Used by FTPClient

    public void setSoTimeout(int soTimeout) {
        this. = soTimeout;
    }
    @Override
    public char getFileSeparator() {
        // the regular ftp component should use the configured separator
        // as FTP servers may require you to use windows or unix style
        // and therefore you need to be able to control that
        PathSeparator pathSeparator = getConfiguration().getSeparator();
        switch (pathSeparator) {
        case :
            return '\\';
        case :
            return '/';
        default:
            return super.getFileSeparator();
        }
    }
New to GrepCode? Check out our FAQ X