Hello,
during the 2020 virtual conf two attendees asked me on how about to upload a file to Nextcloud using curl.
This can be useful to send backups from a machine to your nextcloud e.g. dump your addressbooks to vcf files and save them into your NC. Or dump your NC db and save backup in your NC.
Here are some notes for you.
First create a .netrc file containing your credentials. For help about that please see https://linux.die.net/man/5/netrc
My location for β.netrcβ file is the homedirecty of the user running the script.
Here is a snippet:
BACKUP_PATH="/backup/nextcloud"
LOGDATE=`date +%Y-%m-%d-%H-%M`
LOGFILENAME=/backup/mylog-$LOGDATE.log
curl --netrc -s -S -T /$BACKUP_PATH/db/$LOGDATE-db.sql.gz "https://your.cloud/remote.php/dav/files/<path-on-your-server>/" >> $LOGFILENAME && rm /$BACKUP_PATH/db/$LOGDATE-db.sql.gz
You need to adapt your pathes.
For curl options see the docs at https://linux.die.net/man/1/curl
4 Likes
Hello @sergsqr
see my posting. Maybe you find it already.
Cheers
Perhaps someone like to implement an url-to-nextcloud-download app like part of upload-function from https://github.com/prasathmani/tinyfilemanager
App OcDownloader does not work for me.
1 Like
I would like to add my bash script curl string because it uses direct username:password
curl -k -u "USERNAME:P4s5word" -T "/source/file.txt" "https://your.cloud.tld/remote.php/webdav/<path-on-your-server>/file.txt"
2 Likes
Sorry no real help.
But there is the new app Transfer for uploading with url if you want to upload from web interface from external url.
For your problem maye problem with quotes.
curl -u USERNAME:PASSWORD -T /path/to/file https://my.nextcloud.com/remote.php/dav/files/USERNAME/
How to upload a file via CLI to Nextcloud? (bash)
There is no problem just an example not using netrc and user:passwd in command directly.
If you just want an anonymous upload in a drop folder you can simply use this:
curl -T test.txt "https://YOURNEXTCLOUDADDRESS/public.php/dav/files/YOURSHAREID/test.txt"
Important: add the filename (or path to file) at the end.
Hi! I have a similar question. I wrote a Python script to process several files which users do upload to a group folder and write the result to a file. The script is run manually and saves the file to a nextcloud folder, afterwards I run the occ files:scan to make it available for users.
What I would like is to keep versioning when the script overwrites the result file, plus, add comments to it that the file is updated with indicating timestamp. Looking for the solution.
@knedlyk
Maybe you can create your own thread. But how do you access the directories? If you need occ files:scan, then probably directly via the file system. That is wrong. It is better if you use a Python WebDAV or Python Nextcloud interface. With the Versions app, versioning should also work with WebDAV and Nextcloud interface.
1 Like