I\'m trying to set up an SFTP server with multiple users that each have their own home directory.
I read this answer which explained how to set a virtual directory f
Updated version of above (as of 1.4.0 of sshd-core). Note that I did not specify a file for the host key provider since mine was for a Junit integration test.
List> userAuthFactories = new ArrayList>();
userAuthFactories.add(new UserAuthPasswordFactory());
List> sftpCommandFactory = new ArrayList>();
sftpCommandFactory.add(new SftpSubsystemFactory());
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(22);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(sftpCommandFactory);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
if ((username.equals("admin")) && (password.equals("admin"))) {
sshd.setFileSystemFactory(new VirtualFileSystemFactory(new File("C:\\devl").toPath()));
return true;
}
return false;
}
});
sshd.start();