I was looking for a way to easily upload a file via CLI to a Nextcloud folder that was shared to me, but where I don’t have a user account.

Often those shares are “file drops”, where you can just upload but not list or download the files.

In forums I saw a lot of outdated commands for this that didn’t work, so I quickly want to share the simple command that worked for me:

curl command

curl -u "the-cryptic-part-of-the-url:" \
-T testfile.txt \
"https://my.domain.tld/public.php/webdav/testfile.txt"

So for example if someone shares the URL https://nextcloud.b27.de/index.php/s/Ji4n5WfGinWQqm7 and the file you want to upload is linux-distro.iso it would be the following command in the same directory:

curl -u "Ji4n5WfGinWQqm7:" \
-T linux-distro.iso \
"https://nextcloud.b27.de/public.php/webdav/linux-distro.iso"

If a password is required you put that after the :. This would be Ji4n5WfGinWQqm7:password for the example.

extra header

In one forum I read that for some servers it could help if you add the header

-H "X-Requested-With: XMLHttpRequest"

to the curl command, but I couldn’t verify this yet, because it worked without the header in my first test.