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

僤鯓⒐⒋嵵緔 提交于 2019-11-29 01:53:19

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";
                }
            };
        };
    });
gihan

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

Stefan Winter

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!