I want to download directory from sftp to a server.I am able to login to sftp using

  sftp rob2056@storagename

and then can get individual files using :

   get *.txt /remotedir

But I want to download multiple directories from sftp to remote,which I am not able to do:

    get -r * /remotedir

(does not work)

  • Does not work in what sense? Any error message(s)? – KM. Jan 23 '15 at 19:16
  • it says invalid flag – Ron Jan 23 '15 at 19:17
  • Try get -r /remotedir instead? – KM. Jan 23 '15 at 19:21
  • Thats what it says invalid flag,again – Ron Jan 23 '15 at 19:26
  • Mm. Try with sftp -r rob2056@storagename ... ? I'm starting to suspect your version of sftp may not support -r. In which case you would update it or use another tool like scp. – KM. Jan 23 '15 at 19:30

Is the local directory remote already created before issuing the command get -r * /remotedir ?

I tried this:

  • Created a directory on the local machine remotedir inside which I had to transfer all the folders.

  • Issued the command get -r * remotedir without the slash and it worked. I've no idea why the / matters though.


Use mget instead of get when using metacharacters like ' and ?. You might think of the m as meaning multiple.

  • mget is for multiple files when i am in a directory.I want to download multiple directories.So it does not work in this case.its basically same as get * – Ron Jan 23 '15 at 19:45
mirror -c TestTransfer/ /remotedir

This command can be used to copy the whole directory.

  • Which SFTP client do you use? – hagello Jul 16 '15 at 6:54

Maybe your SFTP client does not know how to mirror directories.

Though there are other SFTP clients. You might want to install a different one or a newer version of your client. The SFTP client in the RedHat package openssh-clients-6.4, for example, knows the -r option.

This is how I got the version of my SFTP client:

rpm -qf /usr/bin/sftp

Apart from that, you might want to do a web search for sftp client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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