简体   繁体   中英

Avoid download of previously downloaded files using Java FTP

我有一个桌面应用程序,可以下载服务器上的所有文件。添加新文件后,我只想下载更新的文件。

Well to know which one is the "new one" you have to create a map/or other datastructure and put pair of the name/metadata creationtime(or last modified time)which one suits you best , when you iterate over your files just see their metadata with

Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

 attr.creationTime(); //or attr.lastModifiedTime(); 

When you compare these times with one on server decide to download only the one with latest time.

Either way you have to keep track of at least the name/time modified(or created) at your previous download and compare these.

If this application on your desktop is not some kind of service that runs nonstop,find some way to persist that data on system,serialization or embed database h2/hsqldb within it.Use streams with conncurent iteration/ parralelStream to check these times and compare ,in case you use java8

edit- to get metadata from url, check this question Get the Last Modified date of an URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM