NIFI-4137: Add support for UTF-8 in GetFTP and PutFTP

Signed-off-by: Yolanda M. Davis <ymdavis@apache.org>

This closes #1957
This commit is contained in:
Matt Burgess 2017-06-28 13:09:55 -04:00 committed by Yolanda M. Davis
parent c99c036c20
commit 9bfa7469cb
3 changed files with 16 additions and 0 deletions

View File

@ -81,6 +81,7 @@ public class GetFTP extends GetFileTransfer {
properties.add(FTPTransfer.PROXY_PORT);
properties.add(FTPTransfer.HTTP_PROXY_USERNAME);
properties.add(FTPTransfer.HTTP_PROXY_PASSWORD);
properties.add(FTPTransfer.UTF8_ENCODING);
this.properties = Collections.unmodifiableList(properties);
}

View File

@ -94,6 +94,7 @@ public class PutFTP extends PutFileTransfer<FTPTransfer> {
properties.add(FTPTransfer.PROXY_PORT);
properties.add(FTPTransfer.HTTP_PROXY_USERNAME);
properties.add(FTPTransfer.HTTP_PROXY_PASSWORD);
properties.add(FTPTransfer.UTF8_ENCODING);
this.properties = Collections.unmodifiableList(properties);
}

View File

@ -105,6 +105,15 @@ public class FTPTransfer implements FileTransfer {
.required(false)
.sensitive(true)
.build();
public static final PropertyDescriptor UTF8_ENCODING = new PropertyDescriptor.Builder()
.name("ftp-use-utf8")
.displayName("Use UTF-8 Encoding")
.description("Tells the client to use UTF-8 encoding when processing files and filenames. If set to true, the server must also support UTF-8 encoding.")
.required(true)
.allowableValues("true", "false")
.defaultValue("false")
.addValidator(StandardValidators.BOOLEAN_VALIDATOR)
.build();
private final ComponentLog logger;
@ -529,6 +538,11 @@ public class FTPTransfer implements FileTransfer {
inetAddress = InetAddress.getByName(remoteHostname);
}
final boolean useUtf8Encoding = ctx.getProperty(UTF8_ENCODING).isSet() ? ctx.getProperty(UTF8_ENCODING).asBoolean() : false;
if (useUtf8Encoding) {
client.setControlEncoding("UTF-8");
}
client.connect(inetAddress, ctx.getProperty(PORT).evaluateAttributeExpressions(flowFile).asInteger());
this.closed = false;
client.setDataTimeout(ctx.getProperty(DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());