How to read files from FTP without download them?

2020-03-31 08:18发布

问题:

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 6 years ago.

In my index file program code i need to access to FTP files and read all of them without download them,how can i do that with org.apache.commons.net library?

回答1:

Well I'm not really sure what you mean by "download". In order to get something via FTP you must issue the FTP GET command which will open a stream towards your client and start sending the bytes of the requested file via that stream. Now most FTP clients gather up all those bytes and write them to a file on the local disk, but you can ofcourse make some Java code that does not do that last part, instead you may choose to write the bytes in memory, or parse them as they come in and discard some of them, etc.

And yes, I do realise that I'm not giving you to the point instructions on how to use Apache's commons net library to do that, because I believe that you should first understand the basics of what you're trying to do before you venture into using a library that makes an abstraction on top of it all.

Look up the basic FTP operations:

http://www.cs.colostate.edu/helpdocs/ftp.html

and the basics of Java I/O first:

http://download.oracle.com/javase/tutorial/essential/io/



回答2:

listFiles() for instance.

http://commons.apache.org/net/apidocs/org/apache/commons/net/ftp/FTPClient.html