How to automatically detect new files in external storage

I have set up a local external storage folder. A document scanner uses SFTP to directly place scanned documents (PDF files) into this directory. However, the desktop client does not seem to sync these files automatically. I have to access the Nextcloud web interface to make that happen.

Is there any way for the Nextcloud desktop client to pick up changes made to an external storage directory?

I’d be happy to have a cron job execute an occ command every couple of minutes, but there does not seem to be one.

This is with NC 18.0.3.


Yes, issue occ files:scan --path=“username/files/path/to/scanned”

You can make a shell script run inotifywait for changed files and issue an occur files:scan.

Thanks very much for your advice. For now I’ve simply added a cron job to execute occ files:scan --path="..." as suggested & this works.

Tried the inotify app from the app store, but that does not seem to work. Will surely attempt the inotify-tools some time…

Got the inotify app working, so no need for additional shell scripting.

For posteriority:

How to watch a local external storage directory for changes

This is with a Dockerized set-up. You’ll want to base this off the example Dockerfile for cron job support because this includes the supervisord process manager.

Install and enable the inotify app within your Nextcloud instance

Find out the ID of the external storage

www-data@docker:/var/www/html$ php occ files_external:list

Watch the external storage

Amend your supervisord.conf file to contain the following:

command=/usr/local/bin/php /var/www/html/occ files_external:notify -v 1

important bits here are the user=www-data line because occ will refuse to operate unless executed as the user who owns the Nextcloud configuration file, which is www-data in the Dockerized setup.

If your external storage ID is not 1, replace -v 1 with whatever is correct for your case.

Don’t forget to restart your Docker image :wink:

1 Like