4

From a directory of dozens of files, is it possible to GET or PUT two files at once using SFTP?

I do not want to use a wildcard because I don't necessarily know the names of all the files and don't want to affect other files.

I'm hoping there's something like:

get javascript.gs,stylesheet.css

From Google searching and looking on various Stackexchanges, it doesn't look like this is possible.

Does anyone know for sure?

3 Answers 3

3

you can do:

sftp user@host << EOF!
get /path/to/file1
get /path/to/file2
EOF!

But personally I prefer to use scp in such cases.

5

If possible, use lftp as your sftp client (available for all the relevant Linux distros and *BSDs in their package collections):

lftp sftp://[email protected]

Then you can use mgetcommand:

mget javascript.gs stylesheet.css

If lftp is not possible to use, then you can use -b (batch) option in standard sftp command. First create a text file containing

get javascript.gs
get stylesheet.css

And then use command

sftp -b yourtextfile.txt [email protected]
2

You can't do this with sftp, the syntax for get is get remote-path [local-path] which means that the second parameter if supplied will be used to rename the file on the local system. Similarly put would rename the uploaded file if a second parameter is supplied.

You could use scp to to the job

scp [email protected]:"/path/to/javascript.gs /path/to/stylesheet.css" /local/path

You could also use an sftp script.

You must log in to answer this question.

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