Upload File to NextCloud/OwnCloud Programmatically

Recently I created a "File Drop" folder that allows anyone who owns the link to upload files. However, I want to drop/upload files programmatically. Luckily, there is an undocumented way to do so.

When you create the "File Drop" folder, it gives you a link with something like:

https://yourdomain.com/index.php/s/xxxxxxx

Let's name the red xs as USERNAME, and the file path to upload is FILEPATH and the target file name is FILENAME. Then we can use cURL to upload the file as follows:

curl -k -T FILEPATH -u "USERNAME:" -H 'X-Requested-With: XMLHttpRequest' -X PUT https://yourdomain.com/public.php/webdav/FILENAME

Leave a comment

Your email address will not be published. Required fields are marked *