使用Apache Commons VFS通过FTP URI导航到根目录

时间:2012-11-21 13:34:48

标签: java apache-commons jsch apache-commons-vfs

我不知道如何从根目录引用文件。目前,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.

1 个答案:

答案 0 :(得分:2)

我找到了解决方案。

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);