+-
Java-Apache Commons VFS:使用FTP
我正在尝试通过FTP使用Apache Commons VFS.在我的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:[email protected]/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());不同的路径.结果:

ftp://user:[email protected]/test-文件

ftp://user:[email protected]/test/in-虚构的

ftp://user:[email protected]/test/in/file1.txt-文件

FileType.IMAGINARY表示该文件不存在.
任何想法如何使用ftp文件夹?

最佳答案
只需为ftp设置“被动”模式:

FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true);
点击查看更多相关文章

转载注明原文:Java-Apache Commons VFS:使用FTP - 乐贴网