Java Code Examples for org.apache.sshd.server.SshServer#setFileSystemFactory()
The following examples show how to use
org.apache.sshd.server.SshServer#setFileSystemFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakeSftpServerRule.java From fake-sftp-server-rule with MIT License | 6 votes |
private SshServer startServer( FileSystem fileSystem ) throws IOException { SshServer server = SshServer.setUpDefaultServer(); server.setPort(port); server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); server.setPasswordAuthenticator(this::authenticate); server.setSubsystemFactories(singletonList(new SftpSubsystemFactory())); /* When a channel is closed SshServer calls close() on the file system. * In order to use the file system for multiple channels/sessions we * have to use a file system wrapper whose close() does nothing. */ server.setFileSystemFactory(session -> new DoNotClose(fileSystem)); server.start(); this.server = server; return server; }
Example 2
Source File: ESBJAVA3470.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Starts a SFTP server on port 22 * @param carbonHome */ private void setupSftpServer(String carbonHome) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(FTP_PORT); //sshd.setKeyPairProvider(new FileKeyPairProvider(new // String[]{"/home/ravi/WORK/SUPPORT/JIRA/SKYTVNZDEV-26/SftpTest/dist/hostkey.ser"})); ClassLoader classLoader = getClass().getClassLoader(); log.info("Using identity file: " + classLoader.getResource("sftp/id_rsa.pub").getFile()); File file = new File(classLoader.getResource("sftp/id_rsa.pub").getFile()); sshd.setKeyPairProvider(createTestHostKeyProvider(Paths.get(file.getAbsolutePath()))); sshd.setUserAuthFactories(Arrays.asList(new UserAuthPublicKeyFactory())); sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(carbonHome))); sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { public boolean authenticate(String username, PublicKey key, ServerSession session) { return "sftpuser".equals(username); } }); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); SftpServerRunner sftpServerRunner = new SftpServerRunner(sshd); try { sftpServerRunner.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 3
Source File: ESBJAVA3470.java From product-ei with Apache License 2.0 | 5 votes |
/** * Starts a SFTP server on port 22 * @param carbonHome */ private void setupSftpServer(String carbonHome) { SshServer sshd = SshServer.setUpDefaultServer(); sshd.setPort(FTP_PORT); //sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"/home/ravi/WORK/SUPPORT/JIRA/SKYTVNZDEV-26/SftpTest/dist/hostkey.ser"})); ClassLoader classLoader = getClass().getClassLoader(); log.info("Using identity file: " + classLoader.getResource("sftp/id_rsa.pub").getFile()); File file = new File(classLoader.getResource("sftp/id_rsa.pub").getFile()); SFTPServer sftpServer = new SFTPServer(); sshd.setKeyPairProvider(sftpServer.createTestHostKeyProvider(Paths.get(file.getAbsolutePath()))); sshd.setKeyPairProvider(createTestHostKeyProvider(Paths.get(file.getAbsolutePath()))); sshd.setUserAuthFactories( Arrays.<NamedFactory<UserAuth>>asList(new UserAuthPublicKeyFactory())); sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(carbonHome))); sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { public boolean authenticate(String username, PublicKey key, ServerSession session) { return "sftpuser".equals(username); } }); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setSubsystemFactories( Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); try { sshd.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: SshdServerConfiguration.java From sshd-shell-spring-boot with Apache License 2.0 | 4 votes |
private void configureServerForSshAndFileTransfer(SshServer server) { server.setCommandFactory(sshAndScpCommandFactory()); server.setFileSystemFactory(new SshdNativeFileSystemFactory(properties.getFilesystem().getBase().getDir())); server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList( new SftpSubsystemFactory.Builder().build())); }