001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.component.file.remote;
019
020 import org.apache.camel.Processor;
021 import org.apache.commons.logging.Log;
022 import org.apache.commons.logging.LogFactory;
023 import org.apache.commons.net.ftp.FTPClient;
024
025 import java.io.IOException;
026
027 public class FtpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> {
028 private static final transient Log log = LogFactory.getLog(FtpEndpoint.class);
029
030 public FtpEndpoint(String uri, RemoteFileComponent remoteFileComponent, RemoteFileConfiguration configuration) {
031 super(uri, remoteFileComponent, configuration);
032 }
033
034 public FtpProducer createProducer() throws Exception {
035 return new FtpProducer(this, createFtpClient());
036 }
037
038 public FtpConsumer createConsumer(Processor processor) throws Exception {
039 final FtpConsumer consumer = new FtpConsumer(this, processor, createFtpClient());
040 configureConsumer(consumer);
041 return consumer;
042 }
043
044 protected FTPClient createFtpClient() throws IOException {
045 final FTPClient client = new FTPClient();
046 String host = getConfiguration().getHost();
047 int port = getConfiguration().getPort();
048 log.debug("Connecting to host: " + host + " port: " + port);
049
050 client.connect(host, port);
051 client.login(getConfiguration().getUsername(), getConfiguration().getPassword());
052 client.setFileType(getConfiguration().isBinary() ? FTPClient.BINARY_FILE_TYPE : FTPClient.ASCII_FILE_TYPE);
053 return client;
054 }
055 }