19

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 user@someRemoteHost.com:/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?

30

Just replace it with:

scp user@someRemoteHost.com:'/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 user@someRemoteHost.com:/folder/*.jpg user@someRemoteHost.com:/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.

  • How can I include all subdirectories of that directory? – pushpen.paul Jul 22 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 user@someRemoteHost.com:'/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 at 12:18
7

Better to use rsync for copying operations between servers.

 rsync -avzh user@remoteip:/path/*.jpg user@192.168.159.155:/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.

  • 8
    No matter if used rsync or scp, the point is that /folder/*.{jpg,png} should quote '/folder/*.{jpg,png}' . – αғsнιη Jan 16 '18 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.