|
33 | 33 | import java.util.concurrent.TimeUnit; |
34 | 34 | import java.util.regex.Pattern; |
35 | 35 |
|
| 36 | +import com.jcraft.jsch.ChannelSftp; |
| 37 | +import com.jcraft.jsch.JSch; |
| 38 | +import com.jcraft.jsch.JSchException; |
| 39 | +import com.jcraft.jsch.ProxyHTTP; |
| 40 | +import com.jcraft.jsch.Session; |
| 41 | +import com.jcraft.jsch.SftpException; |
36 | 42 | import org.apache.nifi.components.PropertyDescriptor; |
37 | 43 | import org.apache.nifi.components.PropertyValue; |
38 | 44 | import org.apache.nifi.flowfile.FlowFile; |
|
41 | 47 | import org.apache.nifi.processor.util.StandardValidators; |
42 | 48 | import org.slf4j.LoggerFactory; |
43 | 49 |
|
44 | | -import com.jcraft.jsch.ChannelSftp; |
45 | 50 | import com.jcraft.jsch.ChannelSftp.LsEntry; |
46 | 51 | import com.jcraft.jsch.ChannelSftp.LsEntrySelector; |
47 | | -import com.jcraft.jsch.JSch; |
48 | | -import com.jcraft.jsch.JSchException; |
49 | | -import com.jcraft.jsch.Session; |
50 | | -import com.jcraft.jsch.SftpException; |
51 | 52 |
|
52 | 53 | public class SFTPTransfer implements FileTransfer { |
53 | 54 |
|
@@ -92,6 +93,39 @@ public class SFTPTransfer implements FileTransfer { |
92 | 93 | .defaultValue("true") |
93 | 94 | .required(true) |
94 | 95 | .build(); |
| 96 | + public static final PropertyDescriptor PROXY_HOST = new PropertyDescriptor.Builder() |
| 97 | + .name("PROXY_HOST") |
| 98 | + .displayName("Proxy Host") |
| 99 | + .description("The fully qualified hostname or IP address of the proxy server") |
| 100 | + .expressionLanguageSupported(true) |
| 101 | + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) |
| 102 | + .build(); |
| 103 | + public static final PropertyDescriptor PROXY_PORT = new PropertyDescriptor.Builder() |
| 104 | + .name("PROXY_PORT") |
| 105 | + .displayName("Proxy Port") |
| 106 | + .description("The port of the proxy server") |
| 107 | + .expressionLanguageSupported(true) |
| 108 | + .addValidator(StandardValidators.PORT_VALIDATOR) |
| 109 | + .build(); |
| 110 | + public static final PropertyDescriptor PROXY_USERNAME = new PropertyDescriptor.Builder() |
| 111 | + .name("PROXY_USERNAME") |
| 112 | + .displayName("Proxy Username") |
| 113 | + .description("Proxy Username") |
| 114 | + .expressionLanguageSupported(true) |
| 115 | + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) |
| 116 | + .required(false) |
| 117 | + .build(); |
| 118 | + public static final PropertyDescriptor PROXY_PASSWORD = new PropertyDescriptor.Builder() |
| 119 | + .name("PROXY_PASSWORD") |
| 120 | + .displayName("Proxy Password") |
| 121 | + .description("Proxy Password") |
| 122 | + .expressionLanguageSupported(true) |
| 123 | + .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) |
| 124 | + .required(false) |
| 125 | + .sensitive(true) |
| 126 | + .build(); |
| 127 | + |
| 128 | + |
95 | 129 |
|
96 | 130 | /** |
97 | 131 | * Dynamic property which is used to decide if the {@link #ensureDirectoryExists(FlowFile, File)} method should perform a {@link ChannelSftp#ls(String)} before calling |
@@ -401,6 +435,18 @@ private ChannelSftp getChannel(final FlowFile flowFile) throws IOException { |
401 | 435 | ctx.getProperty(HOSTNAME).evaluateAttributeExpressions(flowFile).getValue(), |
402 | 436 | ctx.getProperty(PORT).evaluateAttributeExpressions(flowFile).asInteger().intValue()); |
403 | 437 |
|
| 438 | + if (ctx.getProperty(PROXY_HOST).evaluateAttributeExpressions(flowFile).isSet()) { |
| 439 | + final ProxyHTTP proxy = new ProxyHTTP( |
| 440 | + ctx.getProperty(PROXY_HOST).evaluateAttributeExpressions(flowFile).getValue(), |
| 441 | + ctx.getProperty(PROXY_PORT).evaluateAttributeExpressions(flowFile).asInteger() |
| 442 | + ); |
| 443 | + // Check if Username is set and populate the proxy accordingly |
| 444 | + if (ctx.getProperty(PROXY_USERNAME).evaluateAttributeExpressions(flowFile).isSet()) { |
| 445 | + proxy.setUserPasswd(ctx.getProperty(PROXY_USERNAME).evaluateAttributeExpressions(flowFile).getValue(), ctx.getProperty(PROXY_PASSWORD).evaluateAttributeExpressions(flowFile).getValue()); |
| 446 | + } |
| 447 | + session.setProxy(proxy); |
| 448 | + } |
| 449 | + |
404 | 450 | final String hostKeyVal = ctx.getProperty(HOST_KEY_FILE).getValue(); |
405 | 451 | if (hostKeyVal != null) { |
406 | 452 | jsch.setKnownHosts(hostKeyVal); |
|
0 commit comments