通过带有Apache Commons VFS的FTP URI导航到根目录



我不知道如何从根目录引用文件。目前,URI 中的任何路径都是用户目录的子路径。我正在尝试使用此访问/var/www:

sftp://user:password@host/var/www

但它是无效的。

org.apache.commons.vfs2.FileNotFolderException: Could not list the contents of "sftp://user:***@host/var/www" because it is not a folder.

我找到了解决方案。

SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
FileSystemOptions options = new FileSystemOptions();
builder.getKnownHosts(options);
builder.setUserDirIsRoot(options, false);
builder.setTimeout(options, 5000);
FileObject directory = manager.resolveFile("sftp://user:password@host/var/www", options);

最新更新