Manually uploading files and automatically scanning to database

Hi … Have a question I’m having trouble finding an answer to. I have a Nextcloud 21.0.2 install and it’s working great, but as with everything, I’m looking to make it superb. I have a group folder which has a few sub folders inside of. I would like to have one of those sub folders hold text files which are uploaded to the server via TFTP access. I know the files need to be added to the database and can be done with the occ scan command, but I need to have this done automatically. I have TFTP and the sub folder configured so that I can up/download files, but obviously without the automatic scan, the files won’t show in Nextcloud without manually running it all the time.

Specifically, I’m a Network Admin and work with Cisco switches quite a bit. I want to be able to use Nextcloud as a centralized location to upload/download/modify/store switch configurations.

Can this be done?

Thanks!

You could run a cronjob at certain times or you could write a script that copies the files and executes the occ command. The better option would be to use webdav instead of TFTP to upload the files, then no scan would be necessary.

All good ideas, but in my ideal world the files would be scanned “on change” or “on creation” as often times I’m SSH’d into a switch and want to look at a configuration in a text editor. Generally the way I do it now is that I have my laptop set up as a TFTP server so when I’m SSH’d into a switch, I will send the running-config to my laptop and then I can open it with gedit allowing me to see the configuration as a whole so I can search, do a find/replace, copy/paste and so on without having to mess inside of Cisco land. I don’t think I would be able to use webdav as all the up/downloading would be done in a Cisco terminal session; that is unless I create some sort of intermediary “server” which would the sync with Nextcloud… Now that I think of it, that actually may be a solution albeit a clunky one lol

You’re looking for the command “inotifywait”

Yeah. there is not really a good way around using webdav. Because that’s what Nextcloud is in the end. It is based on SabreDAV, which is nothing else than a web/cal/cardDAV server. Maybe you could handcraft something together with the External Storage App. But in my experience it is usually best to use things as they are meant to be used. :wink:

Just add 'filesystem_check_changes' => 1, to your config.php file :slight_smile:

I use that and does exactly what you wish - files are detected and indexed.

Read more about it here

1 Like

That option does NOT work in group folders.

How could I miss that! I did not read the introduction text well enough, my bad!

Thanks for pointing it out, you are 100% correct.

EDIT: I thought that was just for external storage?

I use group folders in my business, on local storage. I wish it was as easy as that flag.

I have to use this script for my network scanner to work, since it doesn’t properly work with webdav;

#!/bin/bash

inotifywait -m /var/www/nextcloud/data/__groupfolders/1/Scan -e create -e moved_to |
	while read path action file; do
		if [[ "$file" =~ .*pdf$ ]]; then
			echo "New file: $path$file"
			/usr/bin/chmod +x /var/www/nextcloud/occ
			chown apache:apache "$path$file"
			echo "Deleting bogus lock file... $path*.LCK"
			rm -rf "$path*.LCK"
			sleep 1
			echo "Adding to Nextcloud."
			sudo -u apache /var/www/nextcloud/occ files:scan --path=scanner/files/Office/Scan
		fi
	done
1 Like

or you can use this :
docker exec --user www-data “yourNCcontainerName” php occ files:scan --all