How to read files from FTP without download them?

2020-03-31 07:58发布

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?

2条回答
祖国的老花朵
2楼-- · 2020-03-31 08:46

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/

查看更多
登录 后发表回答