8

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?

1
  • Is sftp a hard requirement? Would scp suffice?
    – codehead
    Dec 9, 2016 at 0:45

2 Answers 2

11

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.

6

It doesn't work because OpenSSH's sftp doesn't support that. It's mget is the same as get (in fact, mget isn't even documented in help or the manpage), and takes only one remote file name argument (though that argument can be a glob).

So, to use the OpenSSH SFTP client, you'll need to issue one get per file. Alternatively, you could use a different SFTP client (for example, lftp has an mget that works like you want). Or (thanks to Gilles for the reminder) you might find it more convenient to use sshfs (via FUSE) and then use normal file copy commands (cp, or whatever R has built in).

1
  • +1 and my eternal thanks for the lftp pointer.
    – MadHatter
    Apr 14, 2022 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .