Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smart way to copy multiple files from different paths usinc scp

Tags:

scp

ssh

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 cannot put this in configuration files. I know that scp doesn't have a password parameter that I could supply from a script, so for now I must copy each file or directory one by one, writing my password every time.

like image 393
Michele Bortolato Avatar asked Jan 09 '12 09:01

Michele Bortolato


1 Answers

From this site:

Open the master

SSHSOCKET=~/.ssh/myUsername@targetServerName ssh -M -f -N -o ControlPath=$SSHSOCKET myUsername@targetServerName

Open and close other connections without re-authenticating as you like

scp -o ControlPath=$SSHSOCKET myUsername@targetServerName:remoteFile.txt ./

Close the master connection

ssh -S $SSHSOCKET -O exit myUsername@targetServerName

It's intuitive, safer than creating a key pair, faster than creating a compressed file and worked for me!

like image 75
aerijman Avatar answered Sep 25 '22 20:09

aerijman