Search in sources :

Example 1 with FileSystemFactory

use of org.apache.sshd.common.file.FileSystemFactory in project AmazeFileManager by TeamAmaze.

the class AbstractSftpServerTest method createSshServer.

protected final int createSshServer(FileSystemFactory fileSystemFactory, int startPort) throws IOException {
    server = SshServer.setUpDefaultServer();
    server.setFileSystemFactory(fileSystemFactory);
    server.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
    server.setHost("127.0.0.1");
    server.setKeyPairProvider(hostKeyProvider);
    server.setCommandFactory(new ScpCommandFactory());
    server.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));
    server.setPasswordAuthenticator(((username, password, session) -> username.equals("testuser") && password.equals("testpassword")));
    try {
        server.setPort(startPort);
        server.start();
        return startPort;
    } catch (BindException ifPortIsUnavailable) {
        return createSshServer(fileSystemFactory, startPort + 1);
    }
}
Also used : KeyUtils(org.apache.sshd.common.config.keys.KeyUtils) VirtualFileSystemFactory(org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory) KITKAT(android.os.Build.VERSION_CODES.KITKAT) Arrays(java.util.Arrays) SshServer(org.apache.sshd.server.SshServer) BeforeClass(org.junit.BeforeClass) JELLY_BEAN(android.os.Build.VERSION_CODES.JELLY_BEAN) Environment(android.os.Environment) P(android.os.Build.VERSION_CODES.P) AcceptAllPublickeyAuthenticator(org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) IOException(java.io.IOException) BindException(java.net.BindException) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ShadowMultiDex(com.amaze.filemanager.shadows.ShadowMultiDex) Paths(java.nio.file.Paths) TestKeyProvider(com.amaze.filemanager.filesystem.ssh.test.TestKeyProvider) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) After(org.junit.After) FileSystemFactory(org.apache.sshd.common.file.FileSystemFactory) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) Before(org.junit.Before) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) BindException(java.net.BindException)

Aggregations

JELLY_BEAN (android.os.Build.VERSION_CODES.JELLY_BEAN)1 KITKAT (android.os.Build.VERSION_CODES.KITKAT)1 P (android.os.Build.VERSION_CODES.P)1 Environment (android.os.Environment)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 TestKeyProvider (com.amaze.filemanager.filesystem.ssh.test.TestKeyProvider)1 ShadowMultiDex (com.amaze.filemanager.shadows.ShadowMultiDex)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 KeyUtils (org.apache.sshd.common.config.keys.KeyUtils)1 FileSystemFactory (org.apache.sshd.common.file.FileSystemFactory)1 VirtualFileSystemFactory (org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory)1 SshServer (org.apache.sshd.server.SshServer)1 AcceptAllPublickeyAuthenticator (org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator)1 ScpCommandFactory (org.apache.sshd.server.scp.ScpCommandFactory)1 SftpSubsystemFactory (org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory)1 After (org.junit.After)1 Before (org.junit.Before)1