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 17ec08074a..fc39643ccb 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 @@ -355,6 +355,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 { @@ -377,17 +378,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; }