How to read a text file via FTP?

2020-08-09 05:40发布

问题:

I’m creating an application for Android and would like it to be able to read a text file via anonymous FTP.

I've tried URLConnection, but it doesn't seem to be working. After some Google searching it appears that URLConnection doesn't always work with some FTP servers.

All Java FTP connection libraries I've found require you to download the file to a local location before reading it.

However, I would like to have the same functionality as URLConnection in that I can just use the following similar code:

String urlString = "ftp://ftp.domain.com/testing.txt";
URL url = new URL(urlString);
FTPConnection conn = url.openConnection();

BufferedReader reader = new BufferedReader(new InputStreamReader(
                conn.getInputStream()));

回答1:

This comprehensive article compares available Java FTP libraries, explains the two RFCs and their implementations in the SUN JDK and has a lot of more links:

Java FTP client libraries reviewed

And there was a recommendation for Zehon, that seems to be able to download a file to an input stream. Hope it works with android as well.



标签: java android ftp