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?

Nathan C
  • 15,059
  • 4
  • 43
  • 62
Andy Swift
  • 87
  • 2
  • 13

3 Answers3

5

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
Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
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.

Michał Šrajer
  • 856
  • 5
  • 11
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 user@remote.tld:"/path/to/javascript.gs /path/to/stylesheet.css" /local/path

You could also use an sftp script.

user9517
  • 115,471
  • 20
  • 215
  • 297