Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.

share|improve this answer
add comment

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

lftp sftp://someaccount@somehost.com

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 someaccount@somehost.com
share|improve this answer
add comment

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 user@remote.tld:"/path/to/javascript.gs /path/to/stylesheet.css" /local/path

You could also use an sftp script.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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