简体   繁体   English

CURL 中是否有 WGET -N 的等效函数?

[英]Is there an equivilent function in CURL for WGET -N?

我想知道 CURL 是否允许您执行与 WGET -N 相同的功能 - 如果客户端上的现有文件比服务器上的文件旧,它只会下载/覆盖文件。

I realise this question is old now, but just in case someone else is looking for the answer, it seems that cURL can indeed acheieve similar to wget -N.我意识到这个问题现在已经过时了,但以防万一其他人正在寻找答案,似乎 cURL 确实可以实现类似于 wget -N。

Because I was just looking for an answer to this question today, and I found elsewhere that cURL does have time condition option.因为我今天只是在寻找这个问题的答案,我在别处发现cURL确实有时间条件选项。 If google brings you here first, as it did me, then I hope this answer might save you some time in looking.如果谷歌首先将您带到这里,就像我一样,那么我希望这个答案可以为您节省一些时间。 According to curl --help, there is a time-cond flag;根据 curl --help,有一个 time-cond 标志;

-z, --time-cond <time> Transfer based on a time condition

The other part I needed, in order to make it like wget -N, is to make it try and preserve the timestamp.为了使它像 wget -N 一样,我需要的另一部分是尝试保留时间戳。 This is with the -R option.这是使用 -R 选项。

-R, --remote-time   Set the remote file's time on the local output

We can use these to download "$file", only in the condition when the current local "$file" timestamp is older than the server's file timestamp;我们可以使用这些来下载“$file”,只有在当前本地“$file”时间戳比服务器的文件时间戳更旧的情况下; we can do it in this form;我们可以用这种形式来做;

curl -R -o "$file" -z "$file" "$serverurl"

So, for example, I use it to check if there is a newer cygwin installer like this;因此,例如,我用它来检查是否有这样的较新的 cygwin 安装程序;

curl -R -o "C:\cygwin64\setup-x86_64.exe" -z "C:\cygwin64\setup-x86_64.exe" "https://www.cygwin.com/setup-x86_64.exe"

cURL doesn't have the same type of mirroring support that wget has built in. There is one setting in there with cURL that should make it pretty easy to implement this for yourself though with a little bit of wrapping logic. cURL 没有 wget 内置的相同类型的镜像支持。 cURL 中的一个设置应该可以很容易地为自己实现这一点,尽管有一点包装逻辑。 It's the --remote-time option:这是--remote-time选项:

 -R/--remote-time When used, this will make libcurl attempt to figure out the timestamp of the remote file, and if that is available make the local file get that same timestamp.

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

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