Filedrop to Nextcloud via FTP or SMB

Hello, I am trying to find the best way to setup a filedrop via SMB share or FTP. The reason is, that my multi-function printer can store scanned documents to either an FTP server or SMB share (nothing else). So, I was thinking: In theory I could share the file system to another Docker container (I have a Docker Compose setup) that is creating a SMB share of a sub-directory in my account. But afaik, the file will only be known by Nextcloud if I manually run a file system scan in Nextcloud.

The question is: Do you have any better ideas on how to achieve this? I want to be able to scan to my Nextcloud because I want to avoid having to setup SMB on all my PCs and configuring it on the printer for each PC separately.

I think this is not Nextcloud version-specific, so I will skip this information (please let me know I this is wrong).

Thanks!

Hi @schmeckt,

Setup samba and connect your scanner.

Now you can add that samba share as external storage into your Nextcloud.

https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/external_storage/smb.html

External Storage mounted by the files_external (External storage support) App is different. It checks for changed files on every access.


Much and good luck,
ernolf

3 Likes

Nextcloud does not offer SMB or FTP as a server service. Therefore, you always need an FTP server or SMB server as an alternative. Whether you subsequently integrate the FTP storage or SMB storage into your Nextcloud depends on whether you also want the data to be available in your Nextcloud.

More modern multi-function printers may be able to use WebDAV, which can be used to access Nextcloud directly.

1 Like

I implemented a somewhat complicated solution using a separate VM for this, based on the instructions linked below. I did it this way because printers are a security nightmare and I would never let my printer access my Nextcloud VM or my Nextcloud directly, even if it would support WebDAV :wink:

https://thesmarthomejourney.com/2021/12/04/automatic-upload-to-nextcloud/

https://github.com/OliverHi/autouploader

Below i pasted my documentation on how I impemented it, maybe it is of any help:

Scan 2 Cloud

1. Preparations

Setup a separate server or VM and execute the following commands:

sudo apt install samba rclone inotify-tools git
sudo adduser --no-create-home --disabled-password --disabled-login scanner
sudo mkdir /opt/scans
sudo chown scanner /opt/scans/
sudo smbpasswd -a scanner

2. Setup Samba

sudo nano /etc/samba/smb.conf

Comment out the [printers] and [print$] sections like in the example below, or just delete them:

;[printers]
;   comment = All Printers
;   browseable = no
;   path = /var/spool/samba
;   printable = yes
;   guest ok = no
;   read only = yes
;   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
;[print$]
;   comment = Printer Drivers
;   path = /var/lib/samba/printers
;   browseable = yes
;   read only = yes
;   guest ok = no

Add the following lines to the end of the file:

[scans]
comment = Scans folder
path = /opt/scans/
force user = scanner
force group = scanner
writeable = yes
valid users = scanner

If your scanner doesn’t support modern samba versions, add the following line to the [global] section of the file:

server min protocol = NT1

Restart the smb deanon:

sudo systemctl restart smbd.service

3. Configure Rclone

Create a folder “Scans” and an App-Password on the Nextcloud account you want to scan to. After that you can configure Rclone by typing rclone config and following the instruchtions:

rclone config
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n

name> Nextcloud 

Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
[...] 
31 / Webdav
   \ "webdav"
[...]
Storage> 31
** See help for webdav backend at: https://rclone.org/webdav/ **

URL of http host to connect to
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Connect to example.com
   \ "https://example.com"
url> https://cloud.yourdomain.tld/remote.php/dav/files/your-nextcloud-username/Scans

Name of the Webdav site/service/software you are using
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Nextcloud
   \ "nextcloud"
 2 / Owncloud
   \ "owncloud"
 3 / Sharepoint
   \ "sharepoint"
 4 / Other site/service or software
   \ "other"
vendor> 1

User name
Enter a string value. Press Enter for the default ("").
user> your-nextcloud-username

Password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank (default)
y/g/n> y

Enter the password:
password: *the-app-password-previously-generatetd*
Confirm the password:
password: *the-app-password-previously-generatetd*

Bearer token instead of user/pass (eg a Macaroon)
Enter a string value. Press Enter for the default ("").
bearer_token> press ENTER

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

Remote config
--------------------
[Nextcloud]
url = https://cloud.yourdomain.tld/remote.php/dav/files/your-nextcloud-username/Scans
vendor = nextcloud
user = your-nextcloud-username
pass = *** ENCRYPTED ***
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

Current remotes:

Name                 Type
====                 ====
Nextcloud            webdav

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

4. Setup the Inotify Tools

Clone the repository:

sudo git clone https://github.com/OliverHi/autouploader.git /opt/autouploader

Change the value of the DOCUMENT_PATH setting to: /opt/scans in /opt/autouploader/autoupload.sh:

sudo nano /opt/autouploader/autoupload.sh
[...]
# configuration
DOCUMENT_PATH="/opt/scans/"
[...]

Copy your rclone config…

sudo cp ~/.config/rclone/rclone.conf /opt/autouploader/rclone.conf

…and update the ownership:

sudo chown scanner /opt/autouploader/rclone.conf

Install this script as a background service:

sudo ln -s /opt/autouploader/autouploader.service /etc/systemd/system/autouploader.service
sudo systemctl daemon-reload

Enable the service:

sudo systemctl enable autouploader.service

Start the service:

sudo systemctl start autouploader.service

Make sure the service is running:

sudo systemctl status autouploader.service

Check the logs:

journalctl -u autouploader.service -f

Sources:

1 Like

Thank you all very much for the detailed answers. I think setting up another container with Samba and adding it as a external storage to Nextcloud sounds very elegant.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.