wget - 比较文件大小,如果不同则通过 wget 下载

标签 wget

我正在通过 wget 下载一些 .mp3 文件(全部合法):

wget -r -nc files.myserver.com

有时我必须停止下载,此时文件已部分下载。例如,10 分钟的 record.mp3 文件变成 4 分钟的 record.mp3 文件。播放正确,但不完整

如果我使用上面相同的命令,因为 record.mp3 文件已经存在于我的本地计算机中,wget 会跳过该文件,尽管它不完整。

我想知道是否有办法检查文件大小,以及远程服务器和本地计算机中的文件大小是否相同重新下载它。 (我了解到 --spider 命令给出了文件大小,但是否有其他命令可以自动检查文件大小并下载或不下载)。

最佳答案

我会选择 wget 的 -N时间戳选项,但请注意,如果您还指定 --no-if-modified-since,wget 将仅比较文件大小选项。如果没有它,不完整的文件确实会在下次运行时被跳过,因为它们收到当前时间的时间戳,该时间戳比服务器上的时间戳新。

原因可能是只有 -N ,针对设置了 If-Modified-Since 字段的文件发送 GET 请求。服务器响应 200 或 304,但 304 不包含文件大小,因此 wget 无法检查它。

--no-if-modified-since wget 发送一个 HEAD 请求来获取时间戳和文件大小,并检查两者。

我使用什么来递归下载文件夹:

wget -T 300 -nv -t 1 -r -nd -np -l 1 -N --no-if-modified-since -P $my_folder $my_url

与:

-T 300: Set the network timeout to 300 seconds
-nv: Turn off verbose without being completely quiet
-t 1: Set number of tries to 1
-r: Turn on recursive retrieving
-nd: Do not create a hierarchy of directories when retrieving recursively
-np: Do not ever ascend to the parent directory when retrieving recursively
-l 1: Specify recursion maximum depth 1
-N: Turn on time-stamping
--no-if-modified-since: Do not send If-Modified-Since header in ‘-N’ mode, send preliminary HEAD request instead

关于wget - 比较文件大小,如果不同则通过 wget 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31044763/

相关文章:

regex - 如何在 wget 中使用正则表达式来拒绝文件?

linux - centos使用wget下载文件(https),​​在服务器上可用,但在本地虚拟机中停止?

r - wget 选项将输出直接输出到 R

java - 从 WGET 安装 Java 失败

python - HTTP 错误 404 : Not Found when using wget to download a link

linux - 为什么 'wget --page-requisites' 非常慢

linux - 无法使用 wget 下载文件

bash - 检查 wget 的返回值

shell - curl 和 wget : why isn't the GET parameter used?

wget 只下载一个 index.html 文件而不是其他大约 500 个 html 文件