【问题标题】:Is there an equivilent function in CURL for WGET -N?CURL 中是否有 WGET -N 的等效函数?
【发布时间】:2011-09-16 08:02:55
【问题描述】:

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

【问题讨论】:

    标签: windows linux curl


    【解决方案1】:

    我意识到这个问题现在已经过时了,但以防万一其他人正在寻找答案,似乎 cURL 确实可以实现类似于 wget -N。

    因为我今天只是在寻找这个问题的答案,而我在其他地方发现 cURL 确实有时间条件选项。如果谷歌首先把你带到这里,就像我一样,那么我希望这个答案可以为你节省一些时间。根据 curl --help,有一个 time-cond 标志;

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

    为了使它像 wget -N,我需要的另一部分是让它尝试并保留时间戳。这与 -R 选项有关。

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

    我们可以使用这些来下载“$file”,只有在当前本地“$file”时间戳比服务器的文件时间戳更旧的情况下;我们可以这样做;

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

    所以,例如,我用它来检查是否有像这样的较新的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"
    

    【讨论】:

      【解决方案2】:

      cURL 没有 wget 内置的相同类型的镜像支持。cURL 中有一个设置应该可以很容易地为自己实现这一点,尽管有一点包装逻辑。这是--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.
      

      【讨论】:

        猜你喜欢
        • 2023-04-01
        • 1970-01-01
        • 2021-01-20
        • 1970-01-01
        • 1970-01-01
        • 2020-03-10
        • 2019-09-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多