16

I have a Pi running headless using ssh and Screen Sharing on OSX and tightvncserver on raspbian.

Can I copy files from the Mac to/from the Pi using ssh or Screen Sharing (i.e. VNC) or do I need to use Samba or similar?

5
  • 4
    See scp and/or sftp. If your ssh already works, they should be available. There is also an sshfs, which allows mounting of shares a la NFS.
    – goldilocks
    Commented Aug 11, 2013 at 13:03
  • 1
    scp over ssh work fine for me. I myself use Cyberduck for file transfer, as I can just drag and drop, like in finder.
    – Gerben
    Commented Aug 11, 2013 at 15:15
  • 1
    I used sftp (using FileZilla) which got the files there, so query now closed. (I would have marked this as accepted.)
    – Milliways
    Commented Aug 12, 2013 at 0:36
  • Note that ssh encryption can be slow on the Pi. I found blowfish to be fastet CPU wise some years back. Commented Aug 23, 2013 at 6:14
  • NFS is another option and makes the most sense in Unix world as is native.
    – jet
    Commented Sep 7, 2015 at 20:01

9 Answers 9

20

In the 6 years since I posted this Answer many things have changed.
macOS Samba support has improved and Apple now uses Samba as its default for file sharing (and afp doesn't work with newer Apple filesytems)
Debian Buster now uses netatalk 3 - which has significant changes, and requires more configuration to do anything useful.
nfs support in much better in recent Raspbian, but still has problems with write permission from macOS.

I use all of ftp, Samba, afp and nfs;
principally ftp (Filezilla) for routine file transfer to/from the Pi
and Samba for browsing the Pi Home and shared filesystems and to loop mount my backup images for backup/restoration.

I used ftp to solve my problem (as noted above), but recently discovered another method, which other Mac users may find useful.

sudo apt-get install netatalk

Installs the appletalk protocol on the Pi. This lets you use the following (at the terminal prompt on the Mac) to connect to the Pi

open afp://10.1.1.10  (replace this with your Raspberry Pi IP address)

You can then use Finder (or any other FileManager e.g. QuollEyeTree) to transfer files to or from the Pi, using the same techniques you would use on the Mac

Note: This edit is by another user, and AFAIK is unnecessary If you get the error Couldn't get a file descriptor referring to the console with open afp command try again with sudo, also, make sure you have remote login configured on your mac.

4
  • @Paul Fort: as you origianlly added it, what is "open afp command"? Should "afp" be "ftp"? Commented Jul 27, 2014 at 12:10
  • @PeterMortensen have you tried it (or checked the Mac help)?
    – Milliways
    Commented Jul 27, 2014 at 13:41
  • 1
    This is awesome. Love it! Thanks for the tip, was not aware of the ability to do this.
    – gdgr
    Commented Dec 9, 2015 at 23:39
  • Note that, as of 2021, this still works (although Apple has moved on from afp). Also, in its basic configuration, netatalk with restrict logins to the user account (cannot afp as root to gain access to system files).
    – DaveL17
    Commented Sep 1, 2021 at 15:06
7

if you can use ssh, then most probably scp (SSH copy) will work as well.

i would install samba anyway, because there are too many winboxen everywhere and the next thing you might need will be the access from windows.

3
  • I tried scp on the Mac but while this appeared to work no files appeared (I used "sudo scp -v world2 //[email protected]:" and variants). I have used scp (on Pi) to transfer rsa keys. sftp seems the easiest option.
    – Milliways
    Commented Aug 12, 2013 at 0:44
  • scp does not usually require sudo, should work fine without it.
    – lenik
    Commented Aug 12, 2013 at 2:07
  • scp from a Mac to RPi works as expected and doesn't require any additional software on the RPi. netatalk works well too, but of course, adds software and overhead that might only be used occasionally.
    – bobstro
    Commented Oct 1, 2015 at 12:05
3

Did you try scp with the -r flag? Because without it, it won't perform a recursive copy.

If you were looking to copy the file or folder world2, this is how I would do it:

$ scp -rv world2 [email protected]:/path/to/copy/of/world2/
2
  • Excellent command. Quick and easy. Thank you very much. Commented Jun 25, 2016 at 23:28
  • You can make scp much easier to use if you define your hosts in ~/.ssh/config (see nerderati.com/2011/03/17/…) — if you configure your host as rpi, then you can use something like scp -r world2 rpi:/path/to/copy/of/world2/. Just in case it is not obvious, it works the other way too, e.g.: scp rpi:.bashrc somedir. If a path is not absolute then it will be relative to $HOME.
    – ccpizza
    Commented Nov 11, 2017 at 14:16
3

If you have a lot of files, you might also consider using rsync. You'd be able to use the -P flag (for --partial --progress), which is handy when you're anticipating a long transfer with potential interruptions - that way the partially-transferred files will be retained (under normal circumstances they're deleted), so that when you resume the transfer, it won't take as long to finish the transfer.

So in your case you could do:

rsync -avP world2/ [email protected]:world2

(assuming that world2 is a directory, this command would copy the contents of world2 to the /world2 directory on the remote machine)

1

The easiest way I found was using Cyberduck.

  1. Open new connection
  2. Select SFTP from dropdown menu
  3. Server: put the Pi's IP address
  4. Username: should be 'pi'
  5. Password: should be 'raspberry' by default unless you changed it

deselect anonymous login & then connect.

1

If it's a longer term solution, another option is installing Syncthing or Bittorrent Sync on both machines. It keeps directories on multiple machines syncronized and can handle large files and directories. It's very handy as a file server, backup, and for transferring files.

I just switched to Syncthing from btsync. Syncthing provides more options and control (and btsync has proprietary code).

Their Debian/Ubuntu package at apt.syncthing.net worked fine for me and I used this tutorial as a guide

1

Set up SMB sharing on your Pi, http://raspberrywebserver.com/serveradmin/share-your-raspberry-pis-files-and-folders-across-a-network.html

Then, on your Mac, go to finder > go > connect to server (cmd+k) > and enter the address of your pi smb://192.Ras.Pi then you can navigate the folder structure, copy/paste files, etc.

4
  • Why bother posting an answer to a 2 year old question with an accepted answer. This isn't even a good answer, as SMB is a b. of a protocol. If you have a Mac try the answer.
    – Milliways
    Commented Sep 30, 2015 at 23:38
  • Why bother posting an unhelpful comment to a perfectly good answer which is different to every other solution provided? There are multiple ways to move files from one place to another, this one doesn't require installing any other software on the mac, and doesn't require extensive use of the terminal. Why post it on a N years old thread? A) the solution is still good, B) the question is still relevant - I did a google search this morning and this is the first result C) this solution is different than the other solutions provided.
    – jrubins
    Commented Oct 1, 2015 at 4:20
  • I had alluded to this in the original question "or do I need to use Samba or similar" and (implicitly) excluded it.
    – Milliways
    Commented Oct 1, 2015 at 5:12
  • "Or do I need to use Samba or similar" isn't exclusionary language. So, I apologize for giving you a perfectly good answer that (in most cases, since Samba is already installed on many RPi distros) is much easier than any of the other answers provided. I really don't see why you feel the need to argue with my answer and downvote it. Just because you have 5000 reputation on Stack Exchange doesn't mean you aren't being a dickhole.
    – jrubins
    Commented Oct 1, 2015 at 16:19
0

Just use FileZilla and set a new site from site manager on File Menu. Then select SFTP and fill in with you Rasp username and password and you're good to go.

0

Installing MacFusion on your Mac will allow you to mount your Pi over SSH, similar to how you would mount a usb stick on your Mac. Then you can use the finder to copy files to any folder on the Pi as you please.

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.