Multiple connection to remote sftp using same user throwing FileSystemAlreadyExistsException
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 400
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 1
Description
### Description
We did the basic setup for apache mina sshd server and set the FileSystemFactory of sshd (Ex: sshd.setFileSystemFactory(new SftpClientFileSystemFactory());) to connect to remote sftp server. Its working fine with one connection but when we tried to attempt multiple connection using same user it throws FileSystemAlreadyExistsException.
Sample code from custom SftpClientFileSystemFactory
public class SftpClientFileSystemFactory implements FileSystemFactory {
private static final Logger logger = LoggerFactory.getLogger(SftpClientFileSystemFactory.class.getName());
public SftpClientFileSystemFactory() {
}
public Path getUserHomeDir(SessionContext session) throws IOException {
return null;
}
public FileSystem createFileSystem(SessionContext session) throws IOException {
String username = session.getUsername();
FileSystem fs = null;
URI uri = SftpFileSystemProvider.createFileSystemURI("sftp.remote.test", 2022, "user", "pass"); //Example
try {
fs = FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (IOException e) {
logger.error("An error occurred while creating the file system or walking the file tree", e);
}
return fs;
}
}
**sshd server config**
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(22);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPasswordAuthenticator((username, password, session) -> {
return true;
});
sshd.setPublickeyAuthenticator((username, key, session) -> {
return true;
});
sshd.setFileSystemFactory(new SftpClientFileSystemFactory());
sshd.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));
sshd.start();
### Motivation
Wanted to check if this functionality exists or its not valid.
### Alternatives considered
_No response_
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the custom SftpClientFileSystemFactory.createFileSystem method and the FileSystems.newFileSystem call using SftpFileSystemProvider.createFileSystemURI. Run the supplied setup with two sessions using the same user and inspect when FileSystemAlreadyExistsException is raised. Done means establishing whether multiple sessions are supported and documenting or reproducing the expected behavior clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100