JPashs
JPashs

Reputation: 13906

SCP command to copy more than one file from remote to remote server?

I use this command single line to copy a folder named 'myFolder1' from remote server to remote server. It works fine.

I run this command in the 'terminal' of 'myserver2'. This is the destination server, I mean the server the folder will be copied to.

scp -r [email protected]:/home/myserver/www/wp-content/plugins/myFolder1 .

If I need to copy two folders (instead of one)I need to run my command two times (one for each folder) like this:

scp -r [email protected]:/home/myserver/www/wp-content/plugins/myFolder1 .


scp -r [email protected]:/home/myserver/www/wp-content/plugins/myFolder2 .

My question: is there a way to join these two commands into a single command line?

Upvotes: 0

Views: 1831

Answers (2)

James Bear
James Bear

Reputation: 444

The simplest solution is:

scp -r [email protected]:/home/myserver/www/wp-content/plugins/myFolder{1,2} .

An asterick definitely works here, but it matches more than 1 and 2 thus may cause unwanted result. Note that {a,b,c,d} only works on remote path. So if you want to copy from local to remote server, use this instead:

scp -r myFolder1 myFolder2 user@host:/path/

Upvotes: 0

Zanna_37
Zanna_37

Reputation: 152

Yes, there is. Just use the wildcard character * and the quotes ".

Here an example:

scp -r "[email protected]:/home/myserver/www/wp-content/plugins/myFolder*" .

But you can also be more precise using other wildcard characters:

scp -r "[email protected]:/home/myserver/www/wp-content/plugins/myFolder{1,2}" .

💡 Note the quotes used to wrap the path and the wildcard.

Upvotes: 1

Related Questions