Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple connection to remote sftp using same user throwing FileSystemAlreadyExistsException #521

Open
rashmimaharana opened this issue Jun 25, 2024 · 0 comments

Comments

@rashmimaharana
Copy link

rashmimaharana commented Jun 25, 2024

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.<String, Object>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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant