Smart way to copy multiple files from different paths usinc scp

后端 未结 5 867
北荒
北荒 2021-02-08 13:04

I would like to know an easy way to use scp to copy files and folders that are present in different paths on my file system. The ssh destination server requests a password and I

5条回答
  •  情深已故
    2021-02-08 13:21

    If you can express all the names of the files you want to copy from the remote system using a single glob pattern, then you can do this in a single scp command. This usage will only support a single destination folder on the local system for all files though. For example:

    scp 'RemoteHost:/tmp/[abc]*/*.tar.gz' .
    

    copies all of the files from the remote system which are names (something).tar.gz and which are located in subdirectories of /tmp whose names begin with a, b, or c. The single quotes are to protect the glob pattern from being interpreted from the shell on the local system.

    If you cannot express all the files you want to copy as a single glob pattern and you still want the copy to be done using a single command (and a single SSH connection which will ask for your passsword only once) then you can either:

    • Use a different command than scp, like sftp or rsync, or
    • Open an SSH master connection to the remote host and run several scp commands as slaves of that master. The slaves will piggyback on the master connection which stays open throughout and won't ask you for a password. Read up on master & slave connections in the ssh manpage.

提交回复
热议问题