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

前端 未结 3 1181
醉梦人生
醉梦人生 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: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";
                    }
                };
            };
        });
    

提交回复
热议问题