【问题标题】:Navigate to the root directory via FTP URI with Apache Commons VFS使用 Apache Commons VFS 通过 FTP URI 导航到根目录
【发布时间】:2012-11-21 13:34:48
【问题描述】:
我不知道如何从根目录引用文件。目前,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.
【问题讨论】:
标签:
java
apache-commons
jsch
apache-commons-vfs
【解决方案1】:
我找到了解决办法。
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);