How to upload your files to Nextcloud "File Drop" using curl

Jul 24, 2019 by Georgi Nikolov - 1181 views

https://cylab.be/blog/33/how-to-upload-your-files-to-nextcloud-file-drop-using-curl

Nextcloud is a great tool for self-hosting your data in the vein of Dropbox. It facilitates exchange of information and files in a team, with the extra benefit of providing a robust monitoring and protection capabilities. There are Nextcloud clients available for Windows, Linux and MacOS, which are easy to install and use. With one click you can upload your files to your personal cloud and share them. But sometimes the need arises to upload files from machines that don't use a Graphical user Interface (for example Ubuntu Server distribution). Luckily there exists a way to still be able to upload your files to Nextcloud using the command line and Curl.

I encountered this problem while preparing a scenario for one of our classes, where we simulated a virtual network of multiple machines. We had a Windows machine running in a subnet and a File Server and a Honeypot running in a separate subnet. When a user of the network needed to transfer files from and to the File Server, he would use FileZilla. But what about if you want to have a more in-depth look at the log files stored on the File Server or Honeypot? Should you pass through the Windows Machine and use FileZilla to copy the files from those servers to the Win computer? And if you want to upload them to Nextcloud so you can share them with your team? This might seem like a very niche problem, but it is one I encountered recently and spent quite some time finding a solution, where I could upload the log files directly from the File Server and Honeypot to Nextcloud, without using another computer as a middle-man.

Luckily I discovered a short bash script written by someone online, which I will share here with you.

How to upload a file to "File Drop" using curl from command line

  1. If curl is not present on your server you can easily install it using the following command:
$ sudo apt-get update
$ sudo apt-get install curl

You can verify the version of curl with the command curl --version

  1. Create a shared link for a Nextcloud folder. Remember to select the "File Drop (upload only)" option, or "Allow upload and editing" when creating the shared link

Creating a shared link

  1. Download the cloudsend.sh script

We download the script written by Gustavo Arnosti Neves from Github-cloudsend.sh

You can download the script by using curl:

$ curl -O 'https://gist.githubusercontent.com/tavinus/93bdbc051728748787dc22a58dfe58d8/raw/cloudsend.sh' && chmod +x cloudsend.sh

Using chmod +x helps us use the *.sh script as an executable ./cloudsend.sh instead of having to everytime type bash cloudsend.sh

The script is used in the following fashion:

$ ./cloudsend './myfile' 'https://cloud.mydomain.com/s/file-drop-link'

Now we can easily upload files directly to our File Drop Nextcloud link in 3 easy steps. Enjoy!