Apache Commons VFS:使用FTP [英] Apache Commons VFS: working with FTP
问题描述
我正在尝试通过FTP使用Apache Commons VFS.在我的FTP上,具有文件和文件夹的下一个结构:
I'm trying to use Apache Commons VFS with FTP. On my FTP a have the next structure of files and folders:
/
/test
/test/in
/test/in/file1.txt
/test/in/file2.txt
我需要连接并从/test/in文件夹中读取所有文件(它一直在变化).代码:
I need to connect and read all files from folder /test/in (it changes all the time). Code:
FileSystemManager fsManager = null;
FileSystem fs = null;
FileSystemOptions opts = new FileSystemOptions();
fsManager = VFS.getManager();
FileObject path = fsManager.resolveFile("ftp://user:password@my.ftp.host/test/in/", opts);
fs = path.getFileSystem();
//prints Connection successfully established to /test/in
System.out.println("Connection successfully established to " + path.getName().getPath());
但是我没有文件列表,因为它说/test/in不存在.进行了一些测试以检查文件类型:System.out.println(path.getType());
具有不同的路径.结果:
But I couldn't got file list, because it says that /test/in does not exist. A made some tests to check file types:System.out.println(path.getType());
with different paths. Results:
ftp://user:password@my.ftp.host/test -文件
ftp://user:password@my.ftp.host/test/in -虚构
ftp://user:password@my.ftp.host/test/in/file1.txt -文件
FileType.IMAGINARY表示该文件不存在. 有什么想法如何使用ftp文件夹吗?
FileType.IMAGINARY means that file does not exist. Any ideas how to work with ftp folders?
推荐答案
只需为ftp设置被动"模式:
Just set 'passive' mode for ftp:
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
这篇关于Apache Commons VFS:使用FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!