watermark
Nextcloud logo

Adding files to Nextcloud using the command line

 

Say you have a big, multi-gigabyte file that you need to securely share with a client. Then, say attempting to upload it via the Nextcloud web UI, WebDAV and curl had all failed. Now, you could try using one of the Nextcloud sync clients, or you could try this command line instead.

Say your data directory on the server is:/var/www/nextcloud/data//files, so I scp'd the file up to there.

After uploading it, change the owner and group to www-data.

The next step is to ask Nextcloud to re-index your 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="//files" Starting scan for user 1 out of 1 ()
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 3       | 16    | 00:00:02     |
+---------+-------+--------------+

Checking the web UI, the file was shown correctly and you can 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.

Written by

Dan Smith

Development Manager