How to Set Root Directory in Apache Mina Sshd Server in Java

前端 未结 3 1160
醉梦人生
醉梦人生 2020-12-15 22:20

I use Apache Mina Sshd API to start up a local SFTP server in java.In SFTP client i use Jcraft jsch API to create my SFTP client.I successf

相关标签:
3条回答
  • 2020-12-15 22:51

    In more recent sshd versions you can use org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory and supply it to the SshServer instance via method setFileSystemFactory.

    Snippet:

    VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory();
    fileSystemFactory.setDefaultHomeDir("home.directory");
    sshd.setFileSystemFactory(fileSystemFactory)
    
    0 讨论(0)
  • 2020-12-15 22:56

    In Default it takes the root path from System property called user.dir

    Inorder to change this, you can override getVirtualUserDir() in NativeFileSystemView and return your path.

        sshd.setFileSystemFactory(new NativeFileSystemFactory() {
            @Override
            public FileSystemView createFileSystemView(final Session session) {
                return new NativeFileSystemView(session.getUsername(), false) {
                    @Override
                    public String getVirtualUserDir() {
                        return  "C:\\MyRoot";
                    }
                };
            };
        });
    
    0 讨论(0)
  • 2020-12-15 23:06

    You can also follow following link to know about how to set root directory in Apache Mina sshd SFTP server with different sshd-core version.

    <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-core</artifactId>
            <version>0.10.0</version>
        </dependency>
    

    into

    <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-core</artifactId>
            <version>0.14.0</version>
        </dependency>
    

    How to override getVirtualUserDir() in Apache Mina sshd-core version 0.14.0

    0 讨论(0)
提交回复
热议问题