Using mget to download multiple files from sftp

sftp

I have some R code, and at one part, I'm connecting to an sftp and trying to download some files. The files that need to be downloaded are determined by the R code and can either be only one or multiple. I'm trying to use mget to download the files, but it doesn't seem to be working:

sftp> mget abc.PDF  def.PDF ghi.PDF
Fetching /abc.PDF to def.PDF

It is only downloading abc.PDF and storing it as def.PDF on the local directory instead of downloading all three files. What am I doing worng?

Best Answer

mget works with a glob for the "source file" portion of the arguments (at least in OpenSSH version 7.3):

sftp> ls *.pdf
foo.pdf                   bar.pdf                   
sftp> mget *.pdf
Fetching /home/jdoe/bar.pdf to bar.pdf
Fetching /home/jdoe/foo.pdf to foo.pdf
sftp> 

You will instead need to loop over the files somehow and fetch them one-by-one if a glob get catches too many.

Related Question