3

I have two Raspberry Pis, one a 3 running Raspbian Stretch, the other a 4 running Raspbian Bullseye, both headless.

I have need to transfer files from the 3 to the 4 (always in that direction) over the network (copying to/from USB is not ideal).

How would I go about copying files via CLI from one Pi to the other? To start with / to test it'll just be one at a time specified via the command line. It doesn't matter to me whether it's pushed from the 3 or pulled from the 4.

I connect to them both via SSH using Putty from my Windows PC

0

2 Answers 2

2

There are several ways to transfer files from one RPi to another; scp is one way, rsync is another. If it's a file transfer you need to do regularly, you can automate this using rsync, and run it as a cron job. But in keeping with your question to do it from the command line, I'd suggest this:

$ scp -3 pi@raspberrypi3b:/home/pi/test_file.txt pi@raspberrypi4b:/home/pi

What's going on here?

This one-liner xfers the file /home/pi/test_file.txt from a user account named pi on a host named raspberrypi3b to a user account named pi on a host named raspberrypi4b. The -3 option causes the file transfer to go through your local host (the computer from which you have entered the above command).

If you have the SSH key exchange set up between raspberrypi3b and raspberrypi4b, you should be able to copy directly; i.e. the -3 option is no longer needed.

3
2

since you've set up ssh on both, you can just use scp

So, either ssh into the 3, then something like

scp path-on-3/file user@pi4host:path-on-4/file 

or, conversely, ssh into the 4 and

scp user@pi3host:path-on-3/file ./path-on-4/file ... 

obviously user path-on-3 path-on-4 file pi3host and pi4host are placeholders in the commands above and you would have to determine actual values

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.