Pscp utility allows you to transfer/copy files to multiple remote Linux servers using the single terminal with one single command, this tool is a part of Pssh (Parallel SSH Tools), which provides parallel versions of OpenSSH and other similar tools such as:
pscp – is utility for copying files in parallel to a number of hosts.
prsync – is a utility for efficiently copying files to multiple hosts in parallel.
pnuke – it helps to kills processes on multiple remote hosts in parallel.
pslurp – it helps to copy files from multiple remote hosts to a central host in parallel.
When working in a network environment where there are multiple hosts on the network, a System Administrator may find these tools listed above very useful.
To use the pscp tool, you need to install the PSSH utility on your Linux system.
How to Use Pscp to Transfer/Copy Files to Multiple Linux Servers
While using pscp you need to create a separate file that includes the number of Linux server IP address and SSH port number that you need to connect to the server.
Copy Files to Multiple Linux Servers
Let’s create a new file called “myscphosts.txt” and add the list of Linux hosts IP address and SSH port (default 22) number as shown.
129.186.2.5:22 129.186.2.11:22
Once you’ve added hosts to the file, it’s time to copy files from local machine to multiple Linux hosts under /tmp directory with the help of following command.
# pscp -h myscphosts.txt -l rootadminz -Av wine-1.7.55.tar.bz2 /tmp/ OR # pscp.pssh -h myscphosts.txt -l rootadminz -Av wine-1.7.55.tar.bz2 /tmp/
Sample Output
-----------------------------------------------------------------
Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: [1] 17:48:25 [SUCCESS] 129.186.2.5:22 [2] 17:48:35 [SUCCESS] 129.186.2.11:22
Explanation about the options used in the above command:
-h switch used to read a hosts from a given file and location.
-l switch reads a default username on all hosts that do not define a specific user.
-A switch tells pscp ask for a password and send to ssh.
-v switch is used to run pscp in verbose mode.
Copy Directories to Multiple Linux Servers
If you want to copy entire directory use -r option, which will recursively copy entire directories as shown.
# pscp -h myscphosts.txt -l rootadminz -Av -r Android\ Games/ /tmp/ OR # pscp.pssh -h myscphosts.txt -l rootadminz -Av -r Android\ Games/ /tmp/
Sample Output ------------------------------------------------------------------
Warning: do not enter your password if anyone else has superuser privileges or access to your account. Password: [1] 17:48:25 [SUCCESS] 129.186.2.5:22 [2] 17:48:35 [SUCCESS] 129.186.2.11:22