How do I copy a file from multiple servers to my local system?

This is trivial to do with a little script. For example:

for server in app0 app1 app4 app5 appN; do
    scp user@$server:/path/to/log/file /local/path/to/"$server"_file
done

The above will copy the file from each of the servers sequentially and name it SERVERNAME_file. So, the file from app0 will be app0_file etc. You can obviously change the names to whatever you would like.


Use GNU parallel:

parallel -j0 scp {}:/remote_path file_from_{} ::: host1 host2 host3 # and so on

Unlike solutions that use a for, this will run all the downloads in parallel


remote_path="/path/to/file"
local_target_dir="/path/to/dir"
hosts=(app00 app01)
for host in "${hosts[@]}"; do
    scp "$host":"$remote_path" "$local_target_dir"/filename."$host"
done

Tags:

Scp

File Copy