繁体   English   中英

使用 curl 下载最新文件

[英]Downloading most recent file using curl

我需要使用 curl 从远程站点根据文件创建时间下载最新文件。 我怎样才能实现它?

这些是远程站点中的文件

  user-producer-info-etl-2.0.0-20221213.111513-53-exec.jar
  user-producer-info-etl-2.0.0-20221212.111513-53-exec.jar
  user-producer-info-etl-2.0.0-20221214.111513-53-exec.jar
  user-producer-info-etl-2.0.0-20221215.111513-53-exec.jar

以上 user-producer-info-etl-2.0.0-20221215.111513-53-exec.jar 是我要下载的最新文件吗? 我怎样才能实现它?

幸运的是,文件名包含可按字母顺序排序的日期!

我不知道你在哪里,所以我猜你至少有一个 shell,我建议这个 bash 答案:

首先获取最后一个文件名

readonly endpoint="https://your-gitlab.local"

# Get the last filename
readonly most_recent_file="$(curl -s "${endpoint}/get_list_uri"|sort|tail -n 1)"

# Download it
curl -LOs curl "${endpoint}/get/${most_recent_file}"

您显然需要相应地替换网址,但我相信您明白了

  • -L :遵循 HTTP 302 重定向
  • -O :将文件下载到本地目录,保持名称不变
  • -s :静默不显示网络时间和东西

您还可以使用-o <the_most_recent_file>指定另一个本地名称

了解更多信息:

man curl

hth

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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