Use WebDAV with nextcloud

Hello once again. So today, I’m just going to do a quick tutorial on how to use WebDAV with Nextcloud, even though it would probably work with all WebDAV instances. While their docs are pretty good (crazy for an API, right?), I just wanted to have some quick one liners to use with cURL.

Downloading files

This is theoretically an easy one, but how to actually download the file, took me a second to figure out. Since, without the “–output” flag, you just simply read the contents of the file. The “-X GET” isn’t necessary, since cURL sends GET requests by default, but I’d still use it, just for overall compatibility.
curl -X GET -u user:password --output filename.file

Basic uploading and removing of files and folders

So this obviously needs account verification, I made a second account for it, but you can also just use your normal user.

  • Uploading files
    curl -X PUT -u user:password -T filename.file
  • Creating folders
    curl -X MKCOL -u user:password
  • Removing files/folders
    curl -X DELETE -u user:password

    Moving and copying files or folders

    So yeah, I’m not sure why, but it straight up doesn’t work. I don’t know if it worked before, and they broke it with the new update, like with the cron jobs, or my web server is configured wrong. You may refer to the documentation for moving or copying. I might try it again as soon as there’s a new version/docker image, and update the blog if needed.

I hope I could still help you, and have a great rest of your day!

If this article helped you, consider donating.

Sources: - overall documentation