288

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.

asked Sep 12, 2009 at 21:39

Matthew's user avatar

3

427

Use the -R (recursive) flag:

get -R .

AndreyP's user avatar

answered Nov 29, 2010 at 21:38

mani-fresh's user avatar

12

64

Use:

scp -r mpirocch@my-server:/home/mpirocch/Documents Documents

answered Sep 12, 2009 at 21:51

Cristian Ciupitu's user avatar

10

52

Use lftp:

lftp sftp://user@host

Then, within lftp, cd into the directory you want to copy, and use the mirror command to recursively download the selected directory, like this:

mirror

This command accepts options and arguments:

mirror [OPTIONS] [source [target]]

For example, the -R (or --reverse) option will cause it to upload the local directory tree to the remote directory:

mirror -R

See the lftp(1) man page at the project’s site or at Debian.org for other commands and options.

Scott - Слава Україні's user avatar

answered Apr 8, 2010 at 13:54

bshanks's user avatar

0

28

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

lftp sftp://user:password@server.org: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

answered Mar 10, 2014 at 1:18

nwgat's user avatar

3

16

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.

answered Sep 13, 2009 at 3:11

Ryan C. Thompson's user avatar

2

15

get -r [directory]

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

slhck's user avatar

slhck

237k73 gold badges640 silver badges611 bronze badges

answered Mar 6, 2012 at 16:56

drkvogel's user avatar

4

14

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.

answered Sep 12, 2009 at 22:34

Ken Keenan's user avatar

3

2

As with cp:

scp -rp user@host:/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.

Indrek's user avatar

Indrek

25k14 gold badges95 silver badges94 bronze badges

answered Jan 11, 2013 at 9:50

Metalbeard's user avatar

3

0

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

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

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

Step 1. sftp remoteuser@ip

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

answered Sep 28, 2011 at 8:39

YumYumYum's user avatar

0

I recently solved this with lftp:

lftp -c '
open sftp://USER:PASSWORD@remoteserver.example.com:22
mirror --verbose --use-pget-n=8 -c /remote/catalogue/ /local/catalogue/
'

Inspired by this post.

answered Jan 11, 2023 at 9:01

Orphans's user avatar

0

sftp -r user@myserver:/some_remote_directory /tmp/localdir
(it's important to specify the destination directory, otherwise it will just log in)

... worked for me (on Ubuntu 23)

or interactively:

sftp user@myserver
cd some_remote_directory
mget *

(mget stands for "multiple get" and the *-wildcard to get all files)

answered Mar 5, 2024 at 10:04

MacMartin's user avatar

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.