Code for uploading files to Nextcloud

I tried below commands.

https://docs.nextcloud.com/server/15/developer_manual/client_apis/WebDAV/basic.html#uploading-files

But getting error as https not allowed.

Any suggestions?

ok with python,powershell or even curl commands

This works for upload files:

Command is:

I tried this command

C:\Users\uday>curl -k -u ukreddy:password -T “C:\Users\uday\Downloads\gif.gif” “https://10.1.85.219/remote.php/webdav/files/ukreddy/t/gif.gif

<?xml version="1.0" encoding="utf-8"?>

<d:error xmlns:d=“DAV:” xmlns:s=“http://sabredav.org/ns”>
<s:exception>Sabre\DAV\Exception\NotFound</s:exception>
<s:message>File with name files/ukreddy/t could not be located</s:message>
</d:error>

There is folder “t” in my account root folder “ukreddy” can you suggest why this error comes…

1 Like

THank you very much @gas85
It is working. Can you send a command for creating a folder also.

1 Like

Already answered you in other tread:

Just tested it and it works:

curl --user "user:pass" -X MKCOL 'https://DOMAIN/remote.php/webdav/Test_mkcol2'

Can you also send code for uploading complete folder also please

Do not want to be rough, but this cloud help https://duckduckgo.com/?t=ffab&q=webdav+upload+folder+curl
As you will notice there is no build-in way to upload folders, only file by file. In a github you will find different examples, e.g. this for php:

Thanks for the input.

I am running a cronjob on the NC server and wanted it’s output send to my cloud.
I used to put it in user folder and occ files:scan but this is way more elegant :smiley:

This topic solved improved my script but noticed some useful information.

for example my password contains many special characters to escape these characters for ex. !@#$%^&*(){} you should use

curl -u ‘username:P@s5w0rD’

notice the single brackets

for this is very easy if I have many files in /home/user/folder/
and want them in FOLDER1 in the cloud. Make sure FOLDER1 exists on the server or create it.

dir="/home/user/folder/*"; for file in $dir; do curl -k -u ‘username:password’ -T “$file” "https://cloud.example.org/remote.php/webdav/FOLDER1/

If you need to upload to a “Folder With Spaces” replace the spaces with “%20”

dir=“folder/*”; for file in $dir; do curl -k -u ‘username:password’ -T “$file” “https://cloud.example.org/remote.php/webdav/Folder%20With%20Spaces/

this worked for me on bash 5.0.17