Java Apache Mina SSHD 1.0.0设置用户目录&;映射
尝试使用Java中嵌入的ApacheMina SSHD为用户设置主目录 这两种解决方案在1.0版本中都被弃用-Java Apache Mina SSHD 1.0.0设置用户目录&;映射,java,sftp,apache-mina,sshd,mina,Java,Sftp,Apache Mina,Sshd,Mina,尝试使用Java中嵌入的ApacheMina SSHD为用户设置主目录 这两种解决方案在1.0版本中都被弃用- 在0.14.0中,以下各项工作正常: sshd.setFileSystemFactory(new NativeFileSystemFactory() { @Override public FileSystemView createFileSystem(final Session session) { HashMap<String,String>
在0.14.0中,以下各项工作正常:
sshd.setFileSystemFactory(new NativeFileSystemFactory() {
@Override
public FileSystemView createFileSystem(final Session session) {
HashMap<String,String> map = new HashMap<String,String>();
map.put("/", "/Users/someone/Documents");
return new NativeFileSystemView(session.getUsername(), map, "/");
};
});
找到了。我不得不使用
VirtualFileSystemFactory
类
结果是:
VirtualFileSystemFactory fsFactory = new VirtualFileSystemFactory();
fsFactory.setUserHomeDir(userName, realDirectory);
sshd.setFileSystemFactory(fsFactory);
注:
如果您使用的是OS X或linux,请不要忘记先使用chmod
路径。对于v1.2.0(如果是Java 7)/v1.3.0(如果是Java 8)和Java.nio.file.path使用,解决方案可能是:
sshServer.setFileSystemFactory(new VirtualFileSystemFactory(FileSystems.getDefault().getPath(rootDir)));
sshServer.setFileSystemFactory(new VirtualFileSystemFactory(FileSystems.getDefault().getPath(rootDir)));