Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

When I try to use the command get from sftp, I get the error saying that it is not a normal file. Is there a way around this?

share|improve this question

marked as duplicate by Michael Mrozek Jul 10 '13 at 19:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I think you're right... it is a duplicate... but the answer given by @uther is more thorough than the answer given before to the other question... Is there a way to post his answer onto the other question. Since my question is so similarly, feel free to delete my question but please repost his answer on the other question. –  Paul May 23 '12 at 20:09
add comment

1 Answer 1

up vote 13 down vote accepted

You can connect to the host using sftp -r and then get the directory. If you forget to use -r when you connect, you can use get -r.

sftp -r me@somehost

Or

sftp> get -r tmp/
Fetching /home/me/tmp/ to tmp
Retrieving /home/me/tmp
/home/me/new.orig.dmp            100%  417KB 416.8KB/s   00:00    
/home/me/untangle.dmp        100%  398KB 398.3KB/s   00:00    
/home/me/repos.orig.dmp          100%  415KB 415.2KB/s   00:00    
/home/me/me-untangle.dmp 100%   32KB  32.4KB/s   00:00    
sftp>

If you want to always ensure you pass -r to sftp, add it as an alias to your ~/.bashrc or similar.

alias sftp="sftp -r"

From man 1 sftp

 -r      Recursively copy entire directories when uploading and download‐
         ing.  Note that sftp does not follow symbolic links encountered
         in the tree traversal.
         .........

 get [-Ppr] remote-path [local-path]
         ........
         If either the -P or -p flag is specified, then full file permis‐
         sions and access times are copied too.
         If the -r flag is specified then directories will be copied
         recursively.  Note that sftp does not follow symbolic links when
         performing recursive transfers.
share|improve this answer
2  
why does not my sftp client didn't has a -r option? >>>>>sftp: illegal option -- r –  C.C. Sep 16 '12 at 16:59
    
sftp: illegal option -- r on CentOS 6.4 openssh-clients-5.3p1-84.1.el6.x86_64 –  CrackerJack9 Nov 5 '13 at 1:25
add comment

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