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

Sorry for necromancy but this thread shows up high in the search results for “nextcloud client not recognizing changes in external storage” and it is the first and only one that I have found which does give a useful answer – and I have been fighting with this problem literally for years.

The one thing that is lacking is a systemd service file for non-Docker set-ups. I cobbled together a working one and shared it on INotify file watcher (Github).

1 Like

Do you know where the supervisord.conf is on a Docker configuration? Can’t find it

It sits in the root folder. Make sure you use the correct Dockerfile. Please see the links that I posted above. The standard Nextcloud Docker image does not contain supervisord! You need to use the Dockerfile from the examples.

Thank you for the information but I won’t need to modify any files.

After I have installed inotify app in Nextcloud as you mention, it started to detect automaticaly.

Regardless, thank you very much for this post, which led to an actual solution for this ridiculous problem.

Correction. It isn’t working. It worked before because I rebooted Nextcloud after inotify install.

I still need to location for that file.

@bovender you mention, root folder, but I can’t find anywhere. Any chance you can be a bit more specific? I ran a recursive search for the filename and I can’t find it.

Are you sure that your Dockerfile installs containerd and uses it to run Nextcloud? Do you use the Dockerfile from the examples that I recommended, or have you written your own Dockerfile?

Hi @bovender

No, I’m not sure of any of it.
First, I’m not using docker compose. I use the other option where I create the container manually.

Second, I’m using the linuxserver distro for Nextcloud:
docker create
-e PUID=1000
-e PGID=1000
-e TZ=Europe/London
-p 443:443
-v ~/nextcloud/config:/config
-v ~/nextcloud/var/www/data:/data
–restart unless-stopped

Third, I do not have the same folder structure as you show:

I believe all these differences are the cause that I cannot find this file and make the proper configuration. and no, I haven’t followed your previous instructions. Furthermore, this is a Docker system ran over LibreElec and I doubt it uses containerd. Just to add complexity…

Either way, thank you very much for trying to help.

Yeah, you’re probably right. Now I don’t know a thing about LibreElec, but you could try and write your own Dockerfile (or use the one provided in the examples). It’s not a requirement to use docker compose.

Give it a try :slight_smile: Writing Dockerfiles is not that hard to learn :wink:

I feed all my paper mail into an automatic document scanner, and when I sit in the commuter rail later in the morning, all the documents automagically appear on my laptop via Nextcloud, I love it!

1 Like