我正在尝试将 Apache Commons VFS 与 FTP 结合使用。在我的 FTP 上有下一个文件和文件夹结构:
/
/test
/test/in
/test/in/file1.txt
/test/in/file2.txt
我需要连接并读取文件夹/test/in 中的所有文件(它一直在变化)。代码:
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 不存在。 A 做了一些测试来检查文件类型:System.out.println(path.getType());
不同的路径。结果:
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 文件夹有任何想法吗?
最佳答案
只需为 ftp 设置“被动”模式:
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
关于java - Apache Commons VFS : working with FTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6046220/