Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacBH928

macrumors G3
Original poster
May 17, 2008
9,036
4,109
I have a "headless" raspberry pi that has files that I want to SSH into via MacOS terminal and retrieve the files from there, how can I do this?
I was successful by using an app called FileZilla and doing SFTP, but I was wondering if there is a smarter method that doesn't require a third app, after all everything can be controlled from the terminal isn't that right!?
 
You can use sftp from the command line.
sftp user@raspberryip

If you know the path and filename you can use scp
scp user@raspberryip:/path/to/remote/file /path/to/local/destination
 
  • Like
Reactions: bogdanw
Assuming your Pi's IP was 10.0.0.2, open a terminal and connect like so:

Code:
$ sftp username@10.0.0.2

To connect with a hostname instead of an IP, just substitute the IP address with the Pi's hostname:

Code:
$ sftp username@raspberrypihostname

This will give you a connection, but won't download anything. To actually download a file, use "get" like so:

Code:
sftp> get yourfile.txt

To download an entire directory, pass the -r option to get:

Code:
sftp> get -r /remote/directory

To upload files from your Mac to the Pi, use 'put':

Code:
sftp> put localfile.txt

To upload an entire directory, use 'put -r':

Code:
sftp> put -r /local/directory

To see all the remote files, use 'ls':

Code:
sftp> ls



To change directories on the remote system, use 'cd':

Code:
sftp> cd /other/directory

To see the local files in your current local directory (i.e., on your Mac, not on the Pi), use 'lls'. Think of the extra 'l' as meaning local:

Code:
sftp> lls

To change local directories on your Mac, run 'lcd':

Code:
sftp> lcd /other/local/directory

To exit, just type 'exit':

Code:
sftp> exit
 
  • Like
Reactions: MacBH928
Assuming your Pi's IP was 10.0.0.2, open a terminal and connect like so:

Code:
$ sftp username@10.0.0.2

To connect with a hostname instead of an IP, just substitute the IP address with the Pi's hostname:

Code:
$ sftp username@raspberrypihostname

This will give you a connection, but won't download anything. To actually download a file, use "get" like so:

Code:
sftp> get yourfile.txt

To download an entire directory, pass the -r option to get:

Code:
sftp> get -r /remote/directory

To upload files from your Mac to the Pi, use 'put':

Code:
sftp> put localfile.txt

To upload an entire directory, use 'put -r':

Code:
sftp> put -r /local/directory

To see all the remote files, use 'ls':

Code:
sftp> ls



To change directories on the remote system, use 'cd':

Code:
sftp> cd /other/directory

To see the local files in your current local directory (i.e., on your Mac, not on the Pi), use 'lls'. Think of the extra 'l' as meaning local:

Code:
sftp> lls

To change local directories on your Mac, run 'lcd':

Code:
sftp> lcd /other/local/directory

To exit, just type 'exit':

Code:
sftp> exit

Amazing tutorial. thanks for putting the effort
 
Open a terminal window and use the following command:

scp pi@<IP Address of Raspberry Pi>:<Path to File> .
1
scp pi@<IP Address of Raspberry Pi>:<Path to File> .
Using a “.” at the end copies it to your current directory (you can find this out by typing “pwd”). NOTE there is a space between the filename and the “.”

If you want to specify a destination directory, just put it at the end, for example:

scp pi@192.168.1.180:Sleepy-Pi-Setup.sh /users/Jon
1
scp pi@192.168.1.180:Sleepy-Pi-Setup.sh /users/Jon
An example of copying the Sleepy-Pi-Setup.sh from the “Pi” user’s home directory /home/pi to the current directory on the Mac.

scp pi@192.168.1.180:Sleepy-Pi-Setup.sh . (note the dot on the end)


Using SCP to copy a file RPi -> Mac
NOTE: This is done from the Mac Terminal window without being logged in to the Raspberry Pi over SSH.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.