NIFI-4040: Continue if SFTP failed getting user home directory

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #1898.
This commit is contained in:
Koji Kawamura 2017-06-08 16:10:09 +09:00 committed by Pierre Villard
parent 69613f29c9
commit 91ed96f8c4
1 changed files with 10 additions and 3 deletions

View File

@ -396,7 +396,8 @@ public class SFTPTransfer implements FileTransfer {
final JSch jsch = new JSch();
try {
final Session session = jsch.getSession(ctx.getProperty(USERNAME).evaluateAttributeExpressions(flowFile).getValue(),
final String username = ctx.getProperty(USERNAME).evaluateAttributeExpressions(flowFile).getValue();
final Session session = jsch.getSession(username,
ctx.getProperty(HOSTNAME).evaluateAttributeExpressions(flowFile).getValue(),
ctx.getProperty(PORT).evaluateAttributeExpressions(flowFile).asInteger().intValue());
@ -441,10 +442,16 @@ public class SFTPTransfer implements FileTransfer {
if (!ctx.getProperty(USE_KEEPALIVE_ON_TIMEOUT).asBoolean()) {
session.setServerAliveCountMax(0); // do not send keepalive message on SocketTimeoutException
}
try {
this.homeDir = sftp.getHome();
} catch (SftpException e) {
// For some combination of server configuration and user home directory, getHome() can fail with "2: File not found"
// Since homeDir is only used tor SEND provenance event transit uri, this is harmless. Log and continue.
logger.debug("Failed to retrieve {} home directory due to {}", new Object[]{username, e.getMessage()});
}
return sftp;
} catch (final SftpException | JSchException e) {
} catch (JSchException e) {
throw new IOException("Failed to obtain connection to remote host due to " + e.toString(), e);
}
}