TransWikia.com

How to use scp with recursion and file mask for multiple extensions?

Unix & Linux Asked by Renox92 on December 27, 2020

I’m trying to recursively download a directory, but only files with certain extensions from it, while also maintaining the directory structure.

The command I’m using now is
scp -rp user@address:"/path/to/directory/foo/*.{jpg,mp4}" ~/local/directory/foo/. Which a) requires me to create directory foo locally, and b) it only downloads files in the root directory (recursion doesn’t work).

The command I used before this was scp -rp user@address:"/path/to/directory/foo" ~/local/directory/, which didn’t have either of those problems, but downloads all the files I don’t need as well.

One Answer

I don't think this is possible with scp. You can either copy all files recursively or selected file types non-recursively. Note that you don't need to escape the ..

But you could use rsync:

rsync -avm --include='*/' --include='*.jpg' --include='*.mp4' --exclude='*'
  user@address:/path/to/directory/foo ~/local/directory/

Options used:

  • -a archive mode
  • -v increase verbosity
  • -m prune empty directories
  • --include='*/' include subdirectories
  • --include='*.jpg' include *.jpg files
  • --include='*.mp4' include *.mp4 files
  • --exclude='*' exclude other file types

Answered by Freddy on December 27, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP