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 com.jcraft.jsch.ChannelSftp; |
21 |
|
import com.jcraft.jsch.JSch; |
22 |
|
import com.jcraft.jsch.JSchException; |
23 |
|
import com.jcraft.jsch.Session; |
24 |
|
import com.jcraft.jsch.UserInfo; |
25 |
|
import org.apache.camel.Processor; |
26 |
|
|
27 |
0 |
public class SftpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> { |
28 |
|
public SftpEndpoint(String uri, RemoteFileComponent remoteFileComponent, RemoteFileConfiguration configuration) { |
29 |
3 |
super(uri, remoteFileComponent, configuration); |
30 |
3 |
} |
31 |
|
|
32 |
|
public SftpProducer createProducer() throws Exception { |
33 |
0 |
return new SftpProducer(this, createChannelSftp()); |
34 |
|
} |
35 |
|
|
36 |
|
public SftpConsumer createConsumer(Processor processor) throws Exception { |
37 |
0 |
final SftpConsumer consumer = new SftpConsumer(this, processor, createChannelSftp()); |
38 |
0 |
configureConsumer(consumer); |
39 |
0 |
return consumer; |
40 |
|
} |
41 |
|
|
42 |
|
protected ChannelSftp createChannelSftp() throws JSchException { |
43 |
0 |
final JSch jsch = new JSch(); |
44 |
0 |
final Session session = jsch.getSession(getConfiguration().getUsername(), getConfiguration().getHost()); |
45 |
|
|
46 |
0 |
session.setUserInfo(new UserInfo() { |
47 |
|
public String getPassphrase() { |
48 |
0 |
return null; |
49 |
|
} |
50 |
|
|
51 |
|
public String getPassword() { |
52 |
0 |
return SftpEndpoint.this.getConfiguration().getPassword(); |
53 |
|
} |
54 |
|
|
55 |
|
public boolean promptPassword(String string) { |
56 |
0 |
return true; |
57 |
|
} |
58 |
|
|
59 |
|
public boolean promptPassphrase(String string) { |
60 |
0 |
return true; |
61 |
|
} |
62 |
|
|
63 |
|
public boolean promptYesNo(String string) { |
64 |
0 |
return true; |
65 |
|
} |
66 |
|
|
67 |
0 |
public void showMessage(String string) { |
68 |
0 |
} |
69 |
|
}); |
70 |
0 |
session.connect(); |
71 |
0 |
final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); |
72 |
0 |
channel.connect(); |
73 |
0 |
return channel; |
74 |
|
} |
75 |
|
} |