From 91ed96f8c43fece2e92f557ca56a50a48a95dfdf Mon Sep 17 00:00:00 2001 From: Koji Kawamura Date: Thu, 8 Jun 2017 16:10:09 +0900 Subject: [PATCH] NIFI-4040: Continue if SFTP failed getting user home directory Signed-off-by: Pierre Villard This closes #1898. --- .../nifi/processors/standard/util/SFTPTransfer.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java index b5fa3bb459..42fbf8dafd 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/SFTPTransfer.java @@ -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 } - this.homeDir = sftp.getHome(); + 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); } }