| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.component.file.remote; |
| 18 |
|
|
| 19 |
|
import java.io.IOException; |
| 20 |
|
|
| 21 |
|
import org.apache.camel.Processor; |
| 22 |
|
import org.apache.commons.logging.Log; |
| 23 |
|
import org.apache.commons.logging.LogFactory; |
| 24 |
|
import org.apache.commons.net.ftp.FTPClient; |
| 25 |
|
|
| 26 |
0 |
public class FtpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> { |
| 27 |
1 |
private static final transient Log LOG = LogFactory.getLog(FtpEndpoint.class); |
| 28 |
|
|
| 29 |
|
public FtpEndpoint(String uri, RemoteFileComponent remoteFileComponent, RemoteFileConfiguration configuration) { |
| 30 |
3 |
super(uri, remoteFileComponent, configuration); |
| 31 |
3 |
} |
| 32 |
|
|
| 33 |
|
public FtpProducer createProducer() throws Exception { |
| 34 |
0 |
return new FtpProducer(this, createFtpClient()); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
public FtpConsumer createConsumer(Processor processor) throws Exception { |
| 38 |
0 |
final FtpConsumer consumer = new FtpConsumer(this, processor, createFtpClient()); |
| 39 |
0 |
configureConsumer(consumer); |
| 40 |
0 |
return consumer; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
protected FTPClient createFtpClient() throws IOException { |
| 44 |
0 |
final FTPClient client = new FTPClient(); |
| 45 |
0 |
RemoteFileConfiguration config = getConfiguration(); |
| 46 |
0 |
String host = config.getHost(); |
| 47 |
0 |
int port = config.getPort(); |
| 48 |
0 |
LOG.debug("Connecting to host: " + host + " port: " + port); |
| 49 |
|
|
| 50 |
0 |
client.connect(host, port); |
| 51 |
0 |
client.login(config.getUsername(), config.getPassword()); |
| 52 |
0 |
client.setFileType(config.isBinary() ? FTPClient.BINARY_FILE_TYPE : FTPClient.ASCII_FILE_TYPE); |
| 53 |
0 |
return client; |
| 54 |
|
} |
| 55 |
|
} |