I have multiple directories with the same file (remote) and I want to copy them to multiple directories on my local machine.
So lets say remote I have
~/remote_folder/folder1/Myfile.log
~/remote_folder/folder2/Myfile.log
~/remote_folder/folder3/Myfile.log
Do note that next to Myfile.log there are also other files in the folder directories.
And local I want:
~/local_folder/folder1/Myfile.log
~/local_folder/folder2/Myfile.log
~/local_folder/folder3/Myfile.log
Here I only want the Myfile.log and not the other files from the remote.
So what I first had was (I use a bash script):
for folder in ~/remote_folder/*/
do
dirr="$(basename $folder)"
scp "$folder"Myfile.log user@host:~/local_folder/"$dirr"/
done
However this only works for the first 5 folders and then I get connection refused, probably because to many ssh connections.
Does there exist something that I could do this
scp ~/remote_folder/*/Myfile.log user@host:~/local_folder/*/
or something similar, but at least that I can do it with only one ssh connection?
folder1/,folder2/etc. may not exist inlocal_folder/and we need to create them, according to what's in theremote_folder/. Please confirm. Or do all the directories exits already? Canremote_folder/containfolderN/where there is noMyfile.log? Anyway it may be easier if you could treat all paths as local, like with SSHFS. Can you? Please clarify by [edit]ing the question. – Kamil Maciorowski Oct 15 '20 at 15:41remote_folder/contains onlyfolderN's with Myfile.log. What do you mean it may be easier if you could treat all paths as local? – C. Binair Oct 15 '20 at 16:04findorcpthat know nothing about SSH. In this case the most important thing may be that wildcards in a local shell will be able to match local paths that really lead to remote files. If you tell me you can use SSHFS then I will probably be able to help you. Can you install SSHFS on the local computer? Or can you have it installed? – Kamil Maciorowski Oct 15 '20 at 17:28