Reputation: 69
I use Spring Integration SFTP to upload files to a sftp server. When I send some concurrent requests or heavy files, I received Socket Clode exception. But when I send directly the same file with simple Jsch client, even with concurrent calls, everything seems to be ok.
I use default config for both libraries. Spring SFTP uses Jsch, does it configure in such a way it could cause the error ? Is there a special configuration or operation made by Spring but not in the default configuration or behavior than simple Jsch ?
Upvotes: 0
Views: 1285
Reputation: 69
Bean configuration that fixed the problem :
@Bean("speosSessionFactory")
public SessionFactory<ChannelSftp.LsEntry> speosSftpSessionFactory(ApplicationProperties applicationProperties) {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(false);
factory.setHost(applicationProperties.getHost());
factory.setPort(applicationProperties.getPort());
factory.setUser(applicationProperties.getUser());
if (applicationProperties.getPrivateKey() != null) {
factory.setPrivateKey(applicationProperties.getPrivateKey());
factory.setPrivateKeyPassphrase(applicationProperties.getPrivateKeyPassphrase());
} else {
factory.setPassword(applicationProperties.getPassword());
}
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<>(factory, applicationProperties.getMaxSessions());
}
Upvotes: 0
Reputation: 69
The problem is fixed. When setting isSharedSession to true, Spring doesn't close the session, that remains in a pool in order to avoid close/reopen operations. It causes some "Socket Closed" errors with some sftp servers (depending of their config). When using raw jsch client with dedicated session + channel per operation its'ok, using isSharedSession=false is also ok, so in some way, isSharedSession = false could be seen as equivalent to raw jsch operation with open/close for each operation
Upvotes: 1