是否可以使用wget仅下载目录中的最新文件?我知道可以使用选项-nc仅下载尚未下载的文件,但我只希望下载来自ftp://ftp-cdc.dwd.de/pub/CDC/grids_germany/hourly/radolan/recent/的最新单个文件而不是所有(新)文件。目录
答案 0 :(得分:1)
您可以尝试使用其版本号下载最新文件:
final URL url = new URL(remotePath);
final URLConnection connection = url.openConnection();
final int size = connection.getContentLength();
if (size < 0) {
ServerWrapper.getLogger().info("Unable to get the latest version of StarMade!");
} else {
ServerWrapper.getLogger().info("Downloading the latest version of StarMade (length: " + size + " bytes, URL: " + remotePath + ")...");
}
inputStream = new BufferedInputStream(url.openStream());
outputStream = new FileOutputStream("StarMade-latest.zip");
final byte data[] = new byte[1024];
int count;
double sumCount = 0.0;
int percentage;
int lastPercentage = 0;
while ((count = inputStream.read(data, 0, 1024)) != -1) {
outputStream.write(data, 0, count);
sumCount += count;
percentage = (int) Math.ceil(sumCount / size * 100);
if (percentage != lastPercentage) {
ServerWrapper.getLogger().info(percentage + "%");
}
lastPercentage = percentage;
}
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
ServerWrapper.getLogger().info("Download finished. ");
if (isInstalled() && backup) {
ServerWrapper.getLogger().info("Backing up server.");
final File f = new File(new SimpleDateFormat("'backup-'MM-dd hh-mm-ss-SS'.zip'").format(new Date()));
if (!f.exists()) {
f.createNewFile();
}
ZipUtils.zipDirectory(starmadeDirectory, f);
}
if (!starmadeDirectory.exists()) {
starmadeDirectory.mkdirs();
}
ServerWrapper.getLogger().info("Installing update.");
final File starmadeUpdate = new File("starmade-latest.zip");
if (starmadeUpdate.length() != size) {
throw new IOException("File downloaded is the incorrect size!");
}