問題描述
在我的索引文件程序代碼中,我需要訪問 FTP 文件并閱讀所有文件而不下載它們,我如何使用 org.apache.commons.net 庫來做到這一點?
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?
推薦答案
我不太清楚你所說的下載"是什么意思.為了通過 FTP 獲取某些內(nèi)容,您必須發(fā)出 FTP GET 命令,該命令將打開一個流向您的客戶端并開始通過該流發(fā)送請求文件的字節(jié).現(xiàn)在大多數(shù) FTP 客戶端收集所有這些字節(jié)并將它們寫入本地磁盤上的文件,但是您當然可以編寫一些不執(zhí)行最后一部分的 Java 代碼,相反您可以選擇將字節(jié)寫入內(nèi)存或解析它們當他們進來并丟棄其中的一些,等等.
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.
是的,我確實意識到我并沒有向您提供有關如何使用 Apache 的公共網(wǎng)絡庫來做到這一點的重點說明,因為我認為您應該首先了解您正在嘗試做的事情的基礎知識在你冒險使用一個在這一切之上進行抽象的庫之前.
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.
查看基本的 FTP 操作:
Look up the basic FTP operations:
http://www.cs.colostate.edu/helpdocs/ftp.html
首先是 Java I/O 的基礎知識:
and the basics of Java I/O first:
http://download.oracle.com/javase/tutorial/essential/io/
這篇關于如何在不下載的情況下從 FTP 讀取文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!