Scan to OneDrive, SharePoint, Google Drive, DropBox, SSH and More Using a Raspberry Pi and Your Network MFP Scanner

by CraigWrentmore in Circuits > Raspberry Pi

970 Views, 1 Favorites, 0 Comments

Scan to OneDrive, SharePoint, Google Drive, DropBox, SSH and More Using a Raspberry Pi and Your Network MFP Scanner

Scan_Using_Pi.jpg

In a typical office environment, users have access to equipment such as a multi function printer (MFP) that can be used for scanning documents. The simplest and most common setup for these devices involves setting up a shared network folder on a server. Scans are saved into the common folder and anyone using the device can quickly grab the files out of it. As more and more office environments move all on-premise servers and workstations to the cloud it can create some unique challenges regarding scanning to a network folder. The loss of the on-premise server means the only options are to scan to email, scan to a personal workstation, or scan to a cloud based server. Each of these options has their own limitations:

Scan to Cloud directly from the MFP - Many MFPs do not support direct scanning to the cloud at all and those that do often require an additional license with limited functionality. Licenses are very expensive and can cost upwards of $1000 per device.

Scan to email - As soon as files become large the email system can kick them out and users are left wondering why their scan never got delivered. This is more often the case with multi-page scans or scans performed on a large format scanner, such as those made on a plotter scanner, where the file size can become large very quickly.

Scanning to a workstation - The scans are only available to a single user so individual scan folders need to be set up on the MFP for every single workstation. This quickly becomes an administrative burden.

This guide offers a solution to these limitations by making use of a Raspberry Pi and scanning to a standard shared network folder that almost all MFP devices support. The scans will be sent to a shared folder on the Pi which in turn syncs up to a cloud based service such as OneDrive, SharePoint, Google Drive, Dropbox, Citrix Fileshare, and many others. 

As a side benefit, this solution also offers the ability to scan to an SSH/sFTP folder that can be used when folder permissions change due to security concerns. Over the years server security requirements change and items such as SMBv1 protocols get disabled. Any scanners that rely on the protocol no longer function. Although out of the scope of this guide, the solution allows for a similar setup to scan to the Pi and have a service copy the file using SSH to the intended folder, all while keeping security requirements in check.

In this guide we will be scanning to a OneDrive folder. The alternative services are available and are easily configured with some minor changes.

Supplies

Raspberry Pi (any model with ethernet, HMDI, and USB ports)

MicroSD Card (large enough space to store OS and scanned files)

Pi Power Cord

Optional case with fan

Software: Raspberry Pi OS with Desktop, Samba, RClone

Mouse, Keyboard, HDMI Monitor (only needed for setup)

Ethernet cable

Set Up Your Raspberry Pi

Head over to the Raspberry Pi OS download site for the latest Raspberry Pi Imager software, available here: https://www.raspberrypi.com/software/

Download and Install.

Plug in your MicroSD card into your card reader and run Imager

Choose the recommended Raspberry Pi OS with Desktop and choose your MicroSD card.

Write the Image on the card.

Once finished place your MicroSD card in your Raspberry Pi

For simplicity, also hook up an HDMI monitor, USB keyboard and mouse, and an ethernet cable

For the ethernet, plug it into the same network/subnet as your MFP scanning device and the computer that you will be using to configure your Pi.

Boot up your Pi and run through the initial configuration. 

Make a note of your username and password. You will need it when you set up the scan folder. We will use a username of “pi” in following steps.

Skip the WiFi connection screen to keep it on a wired network. Allow check for updates and wait for them to apply.

You will want to give the Pi a static IP address so it does not change. We will use the same IP that was auto-assigned to the Pi so that we know it is not already in use. We also need to know the network gateway address and DNS server.

Open Terminal and enter this command to find the IP address and make a note of it:

hostname -I

Enter this command to find the gateway address and make a note of it (it will be the first IP address listed in the result):

ip r | grep default

Enter this command to find the DNS Server address and make a note of it:

grep “nameserver” /etc/resolv.conf

Now right click the Up/Down arrows in the upper right corner and choose Wireless & Wired Network Settings. Choose Interface and eth0. Uncheck the box for Automatically configure empty options. Click the box to disable ipv6 address. Enter the IP address for the Pi that you noted in the text box for ipv4 address. Enter the gateway address you noted in the text box for Router. Enter the DNS server address that you noted in the text box for DNS Servers. Apply the settings.

Install Samba and RClone

Open Terminal on your Raspberry Pi.

Type this command to install Samba:

sudo apt install samba samba-common-bin

Enter Y when prompted

Type this command to install RClone:

sudo apt install rclone

Set Up the Shared Folder Where Scans Will Be Sent on Your Pi

Open File Manager on your Pi

Create a new folder for the scans. In this example we will create it in the default Home directory and name the folder “scans”. The path is /home/pi/scans

Optional: If you think disk space could be an issue you can also plug in a USB disk drive for added storage. This also adds the benefit of being able to remove your USB drive from your Pi at any time. You may then use your computer to view or delete any files on it. The default path for a USB disk drive is usually in the /media folder.

Open Terminal and type this command to open the Samba configuration file:

sudo nano /etc/samba/smb.conf

Go to the very end of the file and add this section to create a shared folder with read/write permissions:

[scans]
path = /home/pi/scans
writeable = yes
browseable = yes
create mask = 0777
directory mask = 0777
public = no
Notes: Most commands and syntax for configuration on a Pi are case sensitive so always make sure you match the case. If your folder is named “Scans” and not “scans” make sure the path is /home/pi/Scans. The name in the brackets is the actual name that will show up as the shared folder.

Exit and Save the file by using CTRL-X then Y to save and Enter to keep the same name for the file.

Use the following command to create a Samba password for the default username “pi”. In this case we will use the same password as we used when setting up the initial configuration of the Pi.

sudo smbpasswd -a pi

Use this command to restart the Samba service:

sudo systemctl restart smbd

At this point you should be able to browse to the shared folder from your computer. On a PC browse to \\<your static IP>\scans and enter the username/password which is “pi” and the password you just created.

On a Mac open Finder, click Go and Connect to server and enter this in the address box smb://<your static ip>/scans

Set Up the Connection to OneDrive

First, create a folder in your OneDrive account where you would like scans to be delivered. On your computer, log into OneDrive and create a folder. We will use the same user credentials in following steps. You can give permissions to other users within OneDrive as you see fit for your organization.  In this example I’ve created a folder under My Files named “scans”. I’ve shared the folder using access permissions to include a few other people who will need access to the scans.

Open Terminal and type this command:

rclone config

Type n to create a New Remote.

Name the connection onedrivescans

Choose the number associated with Microsoft OneDrive or just type onedrive

Leave the defaults blank for client_id and client_secret and enter n when prompted for Edit Advanced config.

Type y when prompted for Use auto config.

A web browser will open with the standard Microsoft Account login page. Use the same credentials you used earlier to create the OneDrive folder.

Once validated you will see a message stating Success!

Close the web browser.

Choose the option for OneDrive Personal or Business by entering the number (most likely 1).

Choose 0 to select the drive (there should only be one listed)

Choose y and y to confirm the final settings and q to complete the configuration.

You can confirm the connection is working by placing a file in the OneDrive folder and by then typing the following command in Terminal:

rclone ls onedrivescans:

You should see the name of the file show up.

Create an Automated Script to Sync the Folders

On the Pi, go to the Pi menu and choose Accessories, Text Editor

Enter this line:

rclone sync -v /home/pi/scans onedrivescans:scans

This is saying sync the files in the Pi shared folder up to the OneDrive folder. Remember proper case sensitivity in your paths. If you have spaces in your path names you can surround the path with quotes such as “/home/pi/my scans” or “onedrivescans:my scans”

Save the file into the folder /home/pi/Documents by changing the File Type dropdown from Text Files to All Files and naming the file onedrive.sh

Open Terminal and run the following command to make the file an executable.

chmod +x /home/pi/Documents/onedrive.sh

Now we need to schedule the file to run automatically every minute. Type the following command:

crontab -e

Choose the option for nano (usually 1 but could be different)

Scroll down to the bottom of the file and add the following line:

* * * * * /home/pi/Documents/onedrive.sh

Write Out (Save) the file by using CTRL-O and Enter followed by CTRL+X to exit.

Restart your Pi.

Give It a Try!

Everything is ready to go.

On your MFP device set up your scan to folder and point it at your Pi.

Normal settings on an MFP for scan to network folder require the folder path and user credentials to write the file into the folder. In our case the following will be used:

Folder path: \\<static ip address of pi>\scans

Username: pi

Password: the password you set when running the sudo smbpasswd command

Save your scan to network folder and make a scan.

You should see the file show up first in the Pi folder located at \home\pi\scans and about a minute later the file will show up in your OneDrive folder!

Improvements

There is no need to constantly log into the OneDrive account every minute. The only time it is needed is when a new scan file shows up in the shared Pi folder. The automated script can be updated to first check if a new file shows up and then sync only when there is a new file.

Files will continue to build up in the shared Pi folder unless they are manually deleted. Another script can be created and scheduled to automatically remove files from the folder if they are older than a certain number of days.