I have a list of files lying in subdirectories which I have created by calling
for f in $(find . -name "myFile.txt"); do echo "$f" >> filelist.txt; done
The content of
filelist.txt looks like this:
./First/Path/To/File/myFile.txt ./Second/Path/To/File/myFile.txt ./Third/Path/To/File/myFile.txt ...
Now I want to copy all these files to a remote computer such that they are placed in the corresponding folders:
remoteComputerName:/some/root/directory/First/Path/To/File/myFile.txt remoteComputerName:/some/root/directory/Second/Path/To/File/myFile.txt remoteComputerName:/some/root/directory/Third/Path/To/File/myFile.txt
However on the remote computer the folder structure
First/Path/To/File/ etc, does not exist yet and also I don't want to copy the entire directories but only the file
myFile.txt in it.
I know that on a local computer this works using the command
while read p; do cp --parents $p /some/root/directory ; done < filelist.txt
However for remote computers using
scp this option
--parents doesn't work anymore. Also
rsync doesn't create a parent directory if it's missing.
Does someone know a solution?