I tried many different cURL commands to upload/update files on my Nextcloud 18.0.6 server and tested which preserves the original modification timestamp (or accepts a change through the X-OC-Mtime
header):
Uploading a file sets the upload date as file modification time (= does not preserve mtime):
curl -vs -u user:pass -T "/mnt/user/music/song.mp3" "https://example.com/remote.php/webdav/music/song.mp3" 2>&1
Moving the file to the same destination (overwriting) returns the Sabre DAV error “Source and destination uri are identical”:
curl -vs -X MOVE -u user:pass --header 'X-OC-Mtime: 1574254490' --header 'Destination: https://example.com/remote.php/webdav/music/song.mp3' https://example.com/remote.php/webdav/music/song.mp3 2>&1
Moving with overwrite command returns the Sabre DAV error “Source and destination uri are identical”:
curl -vs -X MOVE -u user:pass --header 'X-OC-Mtime: 1574254490' --header 'Overwrite: T' --header 'Destination: https://example.com/remote.php/webdav/music/song.mp3' https://example.com/remote.php/webdav/music/song.mp3 2>&1
Moving to a new destination ignores the X-OC-Mtime:
curl -vs -X MOVE -u user:pass --header 'X-OC-Mtime: 1574254490' --header 'Destination: https://example.com/remote.php/webdav/music/song2.mp3' https://example.com/remote.php/webdav/music/song.mp3 2>&1
New upload with X-OC-MTime “preserves” file modification time:
curl -vs -u user:pass --header 'X-OC-Mtime: 1574254490' -T "/mnt/user/music/song.mp3" "https://example.com/remote.php/webdav/music/song.mp3" 2>&1
Uploading without a file overwrites the already existing file on the server by an empty file and “preserves” the modification time:
curl -vs -X PUT -u user:pass --header 'X-OC-Mtime: 1574254490' "https://example.com/remote.php/webdav/music/song.mp3" 2>&1
Copying the file causes a new copy timestamp (X-OC-Mtime
has been ignored):
curl -vs -X COPY -u user:pass --header 'X-OC-Mtime: 1574254490' --header 'Destination: https://example.com/remote.php/webdav/music/song2.mp3' https://example.com/remote.php/webdav/music/song.mp3 2>&1
The very last command I tried was PROPPATCH
, but I’m not sure if I did it wrong:
curl -vs -X PROPPATCH -u user:pass --header 'Content-Type: application/xml; charset="utf-8"' --data '<?xml version="1.0"?><d:propertyupdate xmlns:d="DAV:" xmlns:nc="http://nextcloud.org/ns"><d:set><d:prop><d:getlastmodified>Mon, 22 Jun 2020 19:20:21 GMT</d:getlastmodified></d:prop></d:set></d:propertyupdate>' "https://example.com/remote.php/webdav/music/song.mp3" 2>&1
It returns the HTTP Header “207 Multi-Status” and the following content:
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:response><d:href>/remote.php/webdav/music/song.mp3</d:href><d:propstat><d:prop><d:getlastmodified/></d:prop><d:status>HTTP/1.1 403 Forbidden</d:status></d:propstat></d:response></d:multistatus>
Do I really need to re-upload all my files to preserve the timestamps or did I miss a command?