Apache Commons VFS:使用FTP [英] Apache Commons VFS: working with FTP

查看:201
本文介绍了Apache Commons VFS:使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆