0

I have a pi-2 and a pi-3 and I am trying to transfer some files from the pi-2 to the pi-3. Is there a way besides using Bluetooth to do it?

  • Bluetooth must be the most difficult way of doing file transfers.. I am amazed you actually got that working... :D – Piotr Kula Nov 30 '17 at 13:25
2

You don't mention what OS nor which image you are running on your raspberries.

As most Linux images already have an ssh-server installed, scp is the easiest solution.

On raspbian-lite images the server is installed but disabled by default. You can start it manually with

$ sudo systemctl start ssh

Even better enabled it to start automatically on each boot with

$ sudo systemctl enable ssh

Once ssh is running it is simple to use:

If you want to push a file from the raspberry you're connected to, to another one:

$ scp localfilename username@otherRapsberryIpAddress:remotefilename

or if you want to get a file from your other raspberry to the one you're connected to:

$ scp username@otherRaspberryIpAddress:remotefilename localfilename

If your username is the same on both raspberries and you want to keep the original filename, it gets even simpler:

$ scp localfile otherRaspberryIpAddress:
$ scp otherRaspberryIpAddress:remotefile .

(don't forget the ':' after the ip address, or the '.' to specify the destination)

There are additional options available if you want to copy recursively whole directories (-R) or define a different port than the normal ssh port (-P).

If you don't have ssh-server installed, just install it, it will be useful in any case. Much easier than to set up a ftp or nfs server.

| improve this answer | |
  • There is no need to do ANYTHING to setup ftp server, unlike ssh which needs to be enabled. – Milliways Dec 1 '17 at 0:14
  • I must disagree with that, even if it might be true in some cases. The original post doesn't mention which image, not even what OS he is running on his raspberries. My answer is based for Raspberries running Raspbian, which comes already with an ssh-server installed. By default it is just not activated, so it must be started first. A minimal Raspbian image doesn't come with a ftp server, not even with an ftp client. Both can of course be installed later. I update my answer. Best regards – Martin Dec 4 '17 at 20:55
2

ftp is probably easiest; scp is also a possibility, but you can use almost any networking protocol.

FileZilla is available in the repository, and easy to use from the GUI, but you can use ftp from the command line.

| improve this answer | |
1

NFS is a very simple to use protocol for filesystem sharing (at least if all nodes are linux based). You can then copy files back and forth as much as you like.

My preference with NFS is use it read-only without encryption. This means the files so shared should not contain sensitive information because anyone could access them, but no one will be able to replace or modify them. If both pis are then set up the same way, they can copy files out of each other.

To illustrate (you first need to sudo install nfs-kernel-server):

  1. Create a directory /opt/nfs.
  2. Edit /etc/exports (it will be empty) and add:

    /opt/nfs     -ro,sync,no_subtree_check 192.168.0.0/24
    

    You can read what the options mean in man exports (those are all actually defaults). The CIDR block at the end should be appropriate to whatever your LAN uses.

  3. Now:

    sudo systemctl start nfs-server
    sudo exportfs -a
    

    The first command starts the nfsd server and such; the second applies what you've put in /etc/exports (it's probably not necessary here, but you will need to use it if you change the contents of export while the server is running). If you are using a firewall you will have to open port 2049 to tcp, udp, and sctp.

  4. On the other pi:

    sudo mkdir /mnt/nfs
    sudo mount -t nfs4 192.168.0.X:/opt/nfs /mnt/nfs
    

    The IP address there should be that of the other pi. You can instead use a hostname if, e.g., you have Avahi set up. You can then make this simpler by adding it to /etc/fstab:

    whatever.hostname:/opt/nfs    /mnt/nfs   nfs   defaults,noauto   0 0
    

    Then you can just use sudo mount /mnt/nfs.

Anything you put in /opt/nfs on the first machine will then be accessible in /mnt/nfs on the second. You can have them both set up this way at the same time (in fact, you can have multiple directories on offer and mount them all remotely). You probably then want the NFS server running at boot (sudo systemctl enable nfs-server).

| improve this answer | |
  • 1
    This is a good guide to using nfs. nfs-server needs to be installed first. This does not work in Jessie (due to a long standing bug with the systemd service), but has been fixed in Stretch. – Milliways Nov 30 '17 at 3:09

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