Adding files to Nextcloud using the command line
I’d got a big, multi gigabyte file that I needed to securely share with a client, and attempting to upload it via the Nextcloud web UI, webDAV and curl had all failed. I could’ve tried using one of the Nextcloud sync clients next, but thought I’d try the command line instead.
My data directory on the server is /var/www/nextcloud/data/<my_username>/files
, so I scp’d the file up to there.
After uploading it, I changed the owner and group to www-data
.
The next step is to ask Nextcloud to re-index my data directory. The command to use is occ
in the /var/www/nextcloud
directory, which you run as the www-data
user:
/var/www/nextcloud$ sudo -u www-data ./occ files:scan --path="/<my_username>/files"
Starting scan for user 1 out of 1 (<my_username>)+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 3 | 16 | 00:00:02 |
+---------+-------+--------------+
Checking the web UI, the file was shown correctly and I was able to share it securely with the client.
This could also be useful if you wanted to add a file directly to another user’s area, saving you from having to download the file to your local machine before uploading it to Nextcloud.
Note: If you have the server-side data encryption option enabled in Nextcloud, then this method won’t work! In that case, you should use one of the sync clients instead.