org.apache.sshd.server.scp.ScpCommandFactory Java Examples
The following examples show how to use
org.apache.sshd.server.scp.ScpCommandFactory.
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: EmbeddedSftpServer.java From java-examples with MIT License | 7 votes |
@Override public void afterPropertiesSet() throws Exception { final PublicKey allowedKey = decodePublicKey(); this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() { @Override public boolean authenticate(String username, PublicKey key, ServerSession session) { return key.equals(allowedKey); } }); this.server.setPort(this.port); this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser"))); this.server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory())); server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP"))); server.setCommandFactory(new ScpCommandFactory()); }
Example #2
Source File: EmbeddedSftpServer.java From java-examples with MIT License | 6 votes |
@Override public void afterPropertiesSet() throws Exception { final PublicKey allowedKey = decodePublicKey(); this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() { @Override public boolean authenticate(String username, PublicKey key, ServerSession session) { return key.equals(allowedKey); } }); this.server.setPort(this.port); this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser"))); this.server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystemFactory())); server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP"))); server.setCommandFactory(new ScpCommandFactory()); }
Example #3
Source File: SftpServerRunner.java From product-ei with Apache License 2.0 | 6 votes |
@Override public void run() { sshd.setPort(port); sshd.setSubsystemFactories( Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path))); sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(final String username, final String password, final ServerSession session) { return StringUtils.equals(username, ftpUser) && StringUtils.equals(password, ftpPassword); } }); try { LOGGER.info("Starting SFTP server on port {}", port); sshd.start(); } catch (IOException e) { LOGGER.error("Error starting SFTP server", e); } }
Example #4
Source File: SftpServerRunner.java From micro-integrator with Apache License 2.0 | 5 votes |
SftpServer(int port, String path, String ftpUser, String ftpPassword) { sshd.setPort(port); sshd.setSubsystemFactories( Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); sshd.setCommandFactory(new ScpCommandFactory()); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); sshd.setFileSystemFactory(new VirtualFileSystemFactory(Paths.get(path))); sshd.setPasswordAuthenticator((username, password, session) -> StringUtils.equals(username, ftpUser) && StringUtils.equals(password, ftpPassword)); }
Example #5
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 #6
Source File: SftpTestResource.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { try { final int port = AvailablePortFinder.getNextAvailable(); sftpHome = Files.createTempDirectory("sftp-"); sshHome = sftpHome.resolve("admin/.ssh"); Files.createDirectories(sshHome); byte[] knownHostsBytes = String.format(KNOWN_HOSTS, port).getBytes(StandardCharsets.UTF_8); Files.write(sshHome.resolve(".known_hosts"), knownHostsBytes); VirtualFileSystemFactory factory = new VirtualFileSystemFactory(); factory.setUserHomeDir("admin", sftpHome.resolve("admin").toAbsolutePath()); sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(port); sshServer.setKeyPairProvider(new ClassLoadableResourceKeyPairProvider("hostkey.pem")); sshServer.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); sshServer.setCommandFactory(new ScpCommandFactory()); sshServer.setPasswordAuthenticator((username, password, session) -> true); sshServer.setPublickeyAuthenticator((username, key, session) -> true); sshServer.setFileSystemFactory(factory); sshServer.start(); return CollectionHelper.mapOf("camel.sftp.test-port", Integer.toString(port)); } catch (Exception e) { throw new RuntimeException(e); } }
Example #7
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 #8
Source File: Server.java From sftpserver with Apache License 2.0 | 5 votes |
protected void setupScp() { sshd.setCommandFactory(new ScpCommandFactory()); sshd.setFileSystemFactory(new SecureFileSystemFactory(db)); sshd.setForwardingFilter(null); sshd.setAgentFactory(null); final int hb = db.getHeartbeat(); if (hb <= 0) { sshd.disableSessionHeartbeat(); } else { sshd.setSessionHeartbeat(HeartbeatType.IGNORE, TimeUnit.SECONDS, hb); } }
Example #9
Source File: SshdServerConfiguration.java From sshd-shell-spring-boot with Apache License 2.0 | 4 votes |
private CommandFactory sshAndScpCommandFactory() { ScpCommandFactory scpCommandFactory = new ScpCommandFactory(); scpCommandFactory.setDelegateCommandFactory(sshCommandFactory(properties.getFilesystem().getBase().getDir())); return scpCommandFactory; }
Example #10
Source File: EmbeddedSSHServer.java From wildfly-camel with Apache License 2.0 | 4 votes |
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }