Guest User

Untitled

a guest
Aug 14th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. public class Minimal
  2. {
  3.     public static void main(String[] args) throws IOException, InterruptedException
  4.     {
  5.         System.out.println("https://github.com/apache/mina-sshd/issues/800");
  6.        
  7.         SshServer sshd = SshServer.setUpDefaultServer();
  8.        
  9.         sshd.setPort(40_000);
  10.        
  11.         sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Path.of("hostkey.ser")));
  12.        
  13.         sshd.setPasswordAuthenticator((u, p, s) -> true);
  14.        
  15.         sshd.setUserAuthFactories(List.of(new UserAuthNoneFactory()));
  16.        
  17.         sshd.setSubsystemFactories(List.of(new SftpSubsystemFactory()));
  18.        
  19.         sshd.setFileSystemFactory(new FileSystemFactory()
  20.         {
  21.             @Override
  22.             public Path getUserHomeDir(SessionContext session) throws IOException
  23.             {
  24.                 return Path.of("/");
  25.             }
  26.            
  27.             @Override
  28.             public FileSystem createFileSystem(SessionContext session) throws IOException
  29.             {
  30.                 System.out.println("filesystem created");
  31.                 return new MyFileSystem();
  32.             }
  33.         });
  34.        
  35.         sshd.start();
  36.        
  37.         System.out.println("Ready!");
  38.        
  39.         Thread.sleep(Integer.MAX_VALUE);
  40.     }
  41.    
  42.     private static class MyFileSystem extends FileSystem
  43.     {
  44.         @Override
  45.         public FileSystemProvider provider()
  46.         {
  47.             System.out.println("this is never called?");
  48.             return null;
  49.         }
  50.        
  51.         @Override
  52.         public void close() throws IOException
  53.         {
  54.             // do nothing
  55.         }
  56.        
  57.         @Override
  58.         public boolean isOpen()
  59.         {
  60.             return true;
  61.         }
  62.        
  63.         @Override
  64.         public boolean isReadOnly()
  65.         {
  66.             return false;
  67.         }
  68.        
  69.         @Override
  70.         public String getSeparator()
  71.         {
  72.             return "/";
  73.         }
  74.        
  75.         @Override
  76.         public Iterable<Path> getRootDirectories()
  77.         {
  78.             return List.of(Path.of("/"));
  79.         }
  80.        
  81.         @Override
  82.         public Iterable<FileStore> getFileStores()
  83.         {
  84.             return List.of();
  85.         }
  86.        
  87.         @Override
  88.         public Set<String> supportedFileAttributeViews()
  89.         {
  90.             return Set.of();
  91.         }
  92.        
  93.         @Override
  94.         public Path getPath(String first, String... more)
  95.         {
  96.             Path result = Path.of(first);
  97.             for (String chunk : more)
  98.             {
  99.                 result = result.resolve(chunk);
  100.             }
  101.             return result;
  102.         }
  103.        
  104.         @Override
  105.         public PathMatcher getPathMatcher(String syntaxAndPattern)
  106.         {
  107.             return null;
  108.         }
  109.        
  110.         @Override
  111.         public UserPrincipalLookupService getUserPrincipalLookupService()
  112.         {
  113.             return null;
  114.         }
  115.        
  116.         @Override
  117.         public WatchService newWatchService() throws IOException
  118.         {
  119.             return null;
  120.         }
  121.     }
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment