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