Issue
This is what I'm trying to achieve:
User uploads file1.jpg to Server A
Using wget Server B only downloads file1.jpg from Server A if the file is newer than the one that already exists on Server B and then replaces the file on Server B with the new one.
I know I can use:
wget -N http://www.mywebsite.com/files/file1.jpg
To check that the target file is newer than the source but I'm a little confused as to how I format the command to let it know what and where the actual source file is?
Is it something like:
wget -N http://www.mywebsite.com/files/file1.jpg /serverb/files/file1.jpg
Solution
You can use -P
option to specify the directory where the file(s) will be downloaded:
$ wget -N -P /serverb/files/ http://www.mywebsite.com/files/file1.jpg
You are also talking about downloading and replacing the file. Be aware, that wget
overwrites the file, so it is "broken" while being downloaded. I don't think you can do atomic replacement of the file using only wget
. You need a small script that uses temporary files and move
to atomically replace the file in Server B.
Answered By - Erki Aring Answer Checked By - Terry (WPSolving Volunteer)