How to upload files to NextCloud using only a shell script
The script Share Link Creator is a handy shell script written in Bash that lets you upload files to you NextCloud-server using the shell.
And yes, I said files as in plural. It allows you to upload multiple files in one go. It will then create a folder named something like
1553524745 (in your predefined upload-folder), upload the files to that folder and then share the public link to the clipboard.
It relies on
xclip and optionally
zenity for graphical notifications with interactive inputs.
It’s a script, there’s not much to do other than downloading the script and making it executable:
$ git clone https://github.com/schiessle/shareLinkCreator
$ cd shareLinkCreator
$ chmod +x shareLinkCreator
Start by copying the file
config.example to a more permanent place like
You only need to change the values
password in the configuration file. The value
uploadTarget is optional and it’s where you want the files to be uploaded.
I have a folder called
tmp and a Cronjob that once a day at midnight deletes files in that folder that’s older than 1 days. The Cronjob looks like this:
00 00 * * * find $HOME/Nextcloud/tmp/* -mtime +1 -delete
You then need to place the script itself somewhere safe and change this line in the script:
. "$(dirname $0)/config"
You want to point it to the configuration file like this:
It’s dead simple:
$ ./shareLinkCreator <file>
And for multiple files:
$ ./shareLinkCreator <file> <file>
When the file is uploaded it will copy the link to you clipboard and give you a notification about it.
I highly recommend setting a $PATH for your shell with all your scripts. You can then call the scripts by their names without the absolute path to the specific directory. Read more about it here.