Sharing files between two RPi devices on the same network

A couple of my students have been using the 'pdfmake' node to create a PDF version of a text-based newsletter. Another student has been using the Telegram node to send messages and photos to a mobile phone. I suggested to them... "why don't you combine what you have done?"
"How about sending the PDF to your colleague who could published it to one or more mobile phones?"
They jumped at this idea, especially when I said you could just FTP the file from one Pi to the other.

When we were doing a review session this week I ( foolishly ) said... "you know you could have done a file-share between the two devices". Their reaction was... "tell us more".

So this coming week I'll be explaining the 'mount' command to them.

I've quickly written a step-by-step tutorial on how to do that for them.

If you would like to, you can preview the material here (via this link)...
http://resources-area.co.uk/node-red-flows/sharing_files.pdf

EDIT: This tutorial was written for my IoT students in their school environment where 'pi' is the user.
As @zenofmud has pointed out to me.. “If either of the Pi’s user names is not ‘pi’ make sure to change it in the various commands within the Tutorial otherwise things won't work.”

5 Likes

Hi Dave
nfs’ defines the type of filing syste, to be used should be nfs’ defines the type of filing system, to be used

As to the technical aspects, I am going to give it a go.

Thanks Jeff for spotting the 'typo' (which has now been corrected on the website).

Dave, did you consider using MQTT or http for file transfer? Would make a good project for your students.

Hi Steve,
A number of the students already use MQTT for their projects. The students I referred to above did initially use MQTT to transfer the PDF from one Pi to another. They then used one of my FTP Python scripts to perform the same task.

It will be interesting to see and hear their reaction to the file sharing method.

One thing I've noticed is... if I perform a... cd /home/pi/my_mount and then a ls command in a Terminal window on the client machine, I don't see any files - which is expected.

If I then mount the filing system and do another ls command, I don't see any files - not expected.

In order to see the files I have to cd to another place and come back again.
e.g. cd /home/pi/my_mount and do ls again - whereupon I do see the files.
I could have done... cd ../my_mount and then ls to achieve the same result.

Is this normal behaviour when doing a remote mount?
Alternatively, it might be something peculiar on my home network/system.

David,
Perhaps you should also tell them that file based transfer data between systems is not always the best solution in real life. In my daily job we are dealing with "lots" of data, some of which is transferred via files. But that gives a lot of headache issues, e.g. monitoring/querying/load distribution/... All kind of troubles that we have solved by communication via Kafka. But of course in other use cases file transfer will be better.

Just to make sure they learn to realize that they cannot use this for every application they come across later on in their jobs. By thinking about this in advance, they can avoid a lot of problems.

Of course fun is the most important factor in your classes I assume, so don't let me spoil that :wink:

Bart

1 Like

It is normal behaviour when doing any mount, remote or local. Think of the directory entry pi_mount as being a road junction. In the unmounted case if you drive down the road from home through the junction into my_mount and look around (ls) you find nothing there. Then the mount operation is performed. This effectively closes the entry from the junction into the road where you are and instead opens a diversion off to the other machine. However, since you are still on the original road there is still nothing there. Drive back up the road past the junction (luckily it is only blocked off in one direction, you can still get out of it) and then drive down the road again and you are directed off to the remote folder.

2 Likes

Have you considered also showing them file sharing using sshfs ?
It's a simpler process but it does rely on knowing a user password on the remote machine, so not ideal for accessing someone else's Pi, good for two pies that you own.

pi@MyPi:~ $ sudo apt install sshfs
...

pi@MyPi:~ $ mkdir myotherpi
pi@MyPi:~ $ sshfs pi@192.168.1.12:/home/pi myotherpi
pi@192.168.1.12's password:

pi@MyPi:~ $ cat myotherpi/hello
Hi there!
This file is on 192.168.1.12

pi@MyPi:~ $ sudo umount myotherpi

Sorry about the red highlighting, not sure where that comes from

1 Like

Thanks Colin for the detailed explanation. It makes complete sense to me now.
I think I'll put a paragraph in the Tutorial in case other people get tripped-up on this "effect" like I did.

Hi Bart,
Thanks for your wise-words of wisdom/experience. I will certainly pass on the information to them.

Thanks for the information about 'sshfs' - my IoT students will be spolit for choice now.

I had problems with fstab being executed during the boot process before the network stack is up and operational, which resulted in not 'seeing' the files in the exported area.

After doing some Goggling I edited my 'fstab' file to include these extra options (and it now works fine)...

192.168.1.152:/home/pi/pdf /home/pi/my_mount nfs defaults,noauto,x-systemd.automount 0 0

Not in the tutorial yet :wink:

Well it is now. Sorry for the delay - it's my Saturday night (here in the UK) with the family.

Note: You might need to refresh your browser's cache to "see" the latest version.

1 Like

Just a thought and maybe this is outside the scope of your lesson but have you considdered sending the file by MQTT? In that way, many devices could subscibe to the topic and recieve the updated file all over the world.

Nick

Yes they have - see post #4 above.

Ahh, sorry. I missed that.