Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Minimal
- {
- public static void main(String[] args) throws IOException, InterruptedException
- {
- System.out.println("https://github.com/apache/mina-sshd/issues/800");
- SshServer sshd = SshServer.setUpDefaultServer();
- sshd.setPort(40_000);
- sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Path.of("hostkey.ser")));
- sshd.setPasswordAuthenticator((u, p, s) -> true);
- sshd.setUserAuthFactories(List.of(new UserAuthNoneFactory()));
- sshd.setSubsystemFactories(List.of(new SftpSubsystemFactory()));
- sshd.setFileSystemFactory(new FileSystemFactory()
- {
- @Override
- public Path getUserHomeDir(SessionContext session) throws IOException
- {
- return Path.of("/");
- }
- @Override
- public FileSystem createFileSystem(SessionContext session) throws IOException
- {
- System.out.println("filesystem created");
- return new MyFileSystem();
- }
- });
- sshd.start();
- System.out.println("Ready!");
- Thread.sleep(Integer.MAX_VALUE);
- }
- private static class MyFileSystem extends FileSystem
- {
- @Override
- public FileSystemProvider provider()
- {
- System.out.println("this is never called?");
- return null;
- }
- @Override
- public void close() throws IOException
- {
- // do nothing
- }
- @Override
- public boolean isOpen()
- {
- return true;
- }
- @Override
- public boolean isReadOnly()
- {
- return false;
- }
- @Override
- public String getSeparator()
- {
- return "/";
- }
- @Override
- public Iterable<Path> getRootDirectories()
- {
- return List.of(Path.of("/"));
- }
- @Override
- public Iterable<FileStore> getFileStores()
- {
- return List.of();
- }
- @Override
- public Set<String> supportedFileAttributeViews()
- {
- return Set.of();
- }
- @Override
- public Path getPath(String first, String... more)
- {
- Path result = Path.of(first);
- for (String chunk : more)
- {
- result = result.resolve(chunk);
- }
- return result;
- }
- @Override
- public PathMatcher getPathMatcher(String syntaxAndPattern)
- {
- return null;
- }
- @Override
- public UserPrincipalLookupService getUserPrincipalLookupService()
- {
- return null;
- }
- @Override
- public WatchService newWatchService() throws IOException
- {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment