Java Code Examples for org.apache.sshd.SshServer#setCommandFactory()

The following examples show how to use org.apache.sshd.SshServer#setCommandFactory() . These examples are extracted from open source projects. 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 Project: pentaho-kettle   File: SftpServer.java    License: Apache License 2.0 6 votes vote down vote up
private SshServer createSshServer( int port, String homeDir, String hostKeyPath ) {
  SshServer server = SshServer.setUpDefaultServer();
  server.setHost( "localhost" );
  server.setPort( port );
  server.setFileSystemFactory( new VirtualFileSystemFactory( homeDir ) );
  server.setSubsystemFactories( Collections.<NamedFactory<Command>>singletonList( new SftpSubsystem.Factory() ) );
  server.setCommandFactory( new ScpCommandFactory() );
  server.setKeyPairProvider( new SimpleGeneratorHostKeyProvider( hostKeyPath ) );
  server.setPasswordAuthenticator( this );
  return server;
}
 
Example 2
Source Project: gerrit-events   File: SshdServerMock.java    License: MIT License 5 votes vote down vote up
/**
 * Starts a ssh server on the provided port.
 *
 * @param port the port to listen to.
 * @param server the server mock to start
 *
 * @return the server.
 * @throws IOException if so.
 */
public static SshServer startServer(int port, SshdServerMock server) throws IOException {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(port);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
        @Override
        public boolean authenticate(String s, PublicKey publicKey, ServerSession serverSession) {
            return true;
        }
    });
    sshd.setCommandFactory(server);
    sshd.start();
    return sshd;
}