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