private SshServer defaultSshServer() { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(randomPort()); ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey); sshServer.setKeyPairProvider(fileKeyPairProvider); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return username.equals(password); } }); sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); ScpCommandFactory commandFactory = new ScpCommandFactory(); commandFactory.setDelegateCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } }); sshServer.setCommandFactory(commandFactory); sshServer.setShellFactory(new ProcessShellFactory("ls")); return sshServer; }
@Override protected Command executeSupportedCommand(String command) { return new ScpCommand(command, getExecutorService(), getSendBufferSize(), getReceiveBufferSize(), getScpFileOpener(), listenerProxy); }
@Override public ScpCommandFactory build() { return factory.clone(); } }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
@Override public Command createCommand(String command) { return new UnknownCommand(command); } }
public Builder withDelegate(CommandFactory delegate) { factory.setDelegateCommandFactory(delegate); return this; }
public Builder withFileOpener(ScpFileOpener opener) { factory.setScpFileOpener(opener); return this; }
public Builder withSendBufferSize(int sendSize) { factory.setSendBufferSize(sendSize); return this; }
public Builder withReceiveBufferSize(int receiveSize) { factory.setReceiveBufferSize(receiveSize); return this; }
public Builder withExecutorService(CloseableExecutorService service) { factory.setExecutorService(service); return this; }
public Builder addEventListener(ScpTransferEventListener listener) { factory.addEventListener(listener); return this; }
public Builder removeEventListener(ScpTransferEventListener listener) { factory.removeEventListener(listener); return this; }
@Override public String toString() { return getClass().getSimpleName() + "(" + getSession() + ") " + command; } }
protected void writeCommandResponseMessage(String command, int exitValue, String exitMessage) throws IOException { if (log.isDebugEnabled()) { log.debug("writeCommandResponseMessage({}) command='{}', exit-status={}: {}", getServerSession(), command, exitValue, exitMessage); } ScpHelper.sendResponseMessage(out, exitValue, exitMessage); }
private CommandFactory sshAndScpCommandFactory() { ScpCommandFactory scpCommandFactory = new ScpCommandFactory(); scpCommandFactory.setDelegateCommandFactory(sshCommandFactory(properties.getFilesystem().getBase().getDir())); return scpCommandFactory; }
public void setupSftp() { this.sshServer.setCommandFactory(new ScpCommandFactory()); this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory())); }
@Override public Command createCommand(String command) { return new UnknownCommand(command); } }
protected void setupScp() { sshd.setCommandFactory(new ScpCommandFactory()); sshd.setFileSystemFactory(new SecureFileSystemFactory(db)); sshd.setTcpipForwardingFilter(null); sshd.setAgentFactory(null); }
@Override public Command createCommand(String command) { return new UnknownCommand(command); } }
private void configureSshdServer(SftpSubsystemFactory factory) { sshdServer.setPort(port); sshdServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser"))); sshdServer.setSubsystemFactories(asList(factory)); sshdServer.setCommandFactory(new ScpCommandFactory()); }