使用cURL上传文件并保留原始时间戳

14

我正在使用curl从FTPS网站下载一些文件。当我将文件从网站下载到我的计算机上时,zip文件的日期会更改为下载的时间和日期。我想保留在FTPS服务器上的原始时间戳。

请指导如何做到这一点。如果您能提供示例,那就太好了,因为我是curl的新手。

谢谢。

1个回答

26

关键在于这个命令行选项:

   -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.

...然后可以像这样使用:

curl -R -O --ssl ftp://example.com/that/file/I/want.txt

(--ssl曾被称为--ftp-ssl)


我尝试了这个,但没有任何反应。我的zip文件仍然以新的下载时间被下载。这是我做的:curl -R myftpsite "我的目标路径"。 - arthur
2
好的,我弄清楚了我做错了什么。如果我执行curl命令而不指定目标路径,它会将zip文件保存在当前目录中,并保留原始时间戳。但是,如果我指定了目标路径,那么zip文件将以新的时间下载。 - arthur
在WSL中,我不得不使用sudo curl ...来避免出现“Failed to set filetime: Operation not permitted”的错误。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接