diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java index 0a9e5b6464..69cf2ea4fb 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/DefaultSftpSessionFactory.java @@ -353,6 +353,7 @@ public class DefaultSftpSessionFactory implements SessionFactory, Share "either a password or a private key is required"); try { JSchSessionWrapper jschSession; + SftpSession sftpSession; if (this.isSharedSession) { this.sharedSessionLock.readLock().lock(); try { @@ -375,17 +376,19 @@ public class DefaultSftpSessionFactory implements SessionFactory, Share this.sharedSessionLock.writeLock().unlock(); } } + jschSession = this.sharedJschSession; + sftpSession = new SftpSession(jschSession); + sftpSession.connect(); } finally { this.sharedSessionLock.readLock().unlock(); } - jschSession = this.sharedJschSession; } else { jschSession = new JSchSessionWrapper(initJschSession()); + sftpSession = new SftpSession(jschSession); + sftpSession.connect(); } - SftpSession sftpSession = new SftpSession(jschSession); - sftpSession.connect(); jschSession.addChannel(); return sftpSession; }