How do I get an entire directory in sftp?

by Matthew   Last Updated September 14, 2018 16:01 PM

I'm just learning to use sftp, and I want to copy a directory from the remote computer to my local computer. If I try

get [directory]

it gives me this error:

Cannot download non-regular file: /home/mpirocch/Documents

get -R doesn't work, either.

Tags : linux sftp

Answers 9


scp -r [email protected]:/home/mpirocch/Documents Documents
Cristian Ciupitu
Cristian Ciupitu
September 12, 2009 21:51 PM

Try mget instead of get.

Clarification: mget will work if you are inside the directory you want to copy; if you do something like this:

sftp> cd dir_to_get
sftp> mget *

it will get all the files in that directory. However, it will not recursively get the contents of any subdirectories.

Ken Keenan
Ken Keenan
September 12, 2009 22:34 PM

Don't use the sftp program directly if you can find something better. For Linux, many file managers (at least Nautilus and Dolphin, the GNOME and KDE ones) support sftp natively, and there's always sshfs. For windows, there's WinSCP, and probably others. The point of all of these is to let you access files over sftp as if they were on a regular filesytem, so you don't have to care that you're accessing them over sftp.

Ryan Thompson
Ryan Thompson
September 13, 2009 03:11 AM

Use lftp:

lftp sftp://[email protected]

Then use the mirror command to recursively upload, like this:

mirror -R

Or to recursively download just:


You have to cd into the directories you want to mirror. Works magically!

April 08, 2010 13:54 PM

Use the -r (recursive) flag:

get -r *
November 29, 2010 21:38 PM

I have Java dist folder in remote server, where i have following tree:

- dist
--- Audio.jar
--- lib
----- lib.jar

Goal is: I want to use SFTP? And put them in /tmp/<>

Step 1. sftp [email protected]

Step 2. cd /var/tmp

Step 2. lmkdir /tmp/dist; lmkdir /tmp/dist/lib

Step 3. lcd /tmp/dist

Step 4. mget *

Step 5. lcd /tmp/dist/lib

Step 6. mget *

Step 7. finally i have my goal

$ ls
Audio.jar  lib  README.TXT
September 28, 2011 08:39 AM

get -r [directory]

gets [directory] and everything under it, where r stands for recursive. I found this just by typing help from sftp.

March 06, 2012 16:56 PM

As with cp:

scp -rp [email protected]:/path/to/dir dir

The above will preserve times and modes of the original files and subdirectories. This is especially useful for the retrieval of backups.

January 11, 2013 09:50 AM

well this little guide should help, mirror a remote server to local folder with lftp

lftp sftp://user:[email protected]:22 -e 'mirror --verbose --use-pget-n=8 -c /remote/path /local/path'

  • sftp:// = uses SFTP protocol
  • mirror = mirror mode
  • verbose = shows the files being downloaded
  • use-pget-n = number of segments, realy useful to speed up big files
  • parallel = downloads multiplier files at the same time

if you want to download files in parallel switch out use-pget-n=8 with --parallel=8

hope this helps anyone needing to mirror a remote folder to a local folder

March 10, 2014 01:18 AM

Related Questions

I want to copy files from SFTP to another server

Updated April 30, 2017 01:01 AM

SFTP mirroring from server to linux machine

Updated November 30, 2017 08:01 AM

Host key verification failed

Updated October 05, 2016 09:00 AM