31

I want to copy over .jpg and .png files with scp, but there files with different extensions in the same folder I'm copying from. I am doing the following:

scp [email protected]:/folder/*.{jpg,png} .

I am asked to enter my password for each extension type. Is there a way to do this in such a way that I enter my password only once?

2 Answers 2

49

Just replace it with:

scp [email protected]:'/folder/*.{jpg,png}' .

Please note the pair of single quotes. In your case, your local shell is evaluating the expression, turning it really into:

scp [email protected]:/folder/*.jpg [email protected]:/folder/*.png .

hence the two passwords asked. In this solution, the pair of single quotes protects it from evaluation by the local shell, so it's the remote shell called by (the remote) scp which is evaluating the expression.

3
  • 2
    How can I include all subdirectories of that directory?
    – hola
    Jul 22, 2019 at 14:54
  • @pushpen.paul If you don't need to select only png and jpg files but want to copy everything, then using for example scp -r [email protected]:'/folder' . should do it. Else if you still want to copy only png and jpg in those subdirectories you probably can't use scp or sftp (unless sftp/lftp with possible custom script) but need to run something like ssh + a pair of tar instead. You'd have to ask your own question with the specific needs then.
    – A.B
    Jul 24, 2019 at 12:18
  • double quotes " also work besides single ones.
    – Timo
    Apr 28, 2022 at 10:13
15

Better to use rsync for copying operations between servers.

 rsync -avzh user@remoteip:/path/*.jpg [email protected]:/path/*.png localserverpath

Using rsync it will asks for password only one time.

Also in rsync while transferring the file it will check in the target location if the file exists or not and also check whether content is same or not in source location and target location.

If file also exists in target location and the contents are also the same, then it won't copy that file. It will only copy the files which don't exist in the target location, so it reduces processing time.

rsync is often used as an incremental backup tool.

1
  • 12
    No matter if used rsync or scp, the point is that /folder/*.{jpg,png} should quote '/folder/*.{jpg,png}' . Jan 16, 2018 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .