2012-11-21 114 views
1

通過FTP URI導航到根目錄我不知道如何從根目錄引用文件。目前,URI中的任何路徑都是用戶目錄的子節點。我試圖訪問/ var/www與此:使用Apache Commons VFS

sftp://user:[email protected]/var/www 

但它是無效的。

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

回答

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:[email protected]/var/www", options); 
+0

工作就像一個魅力!萬分感謝 –

相關問題