Use inotifywait and lftp to synchronize servers
- by KBoek
I have two servers:
Server A (CentOS), where people can upload files to (upload root is /files)
Server B (Win 2008), with FileZilla FTP Server (FTP root is C:\content)
I want that whenever a file is uploaded to Server A, to any subfolder under /files, the file is automatically copied to the exact same subfolder on Server B. Thus, if a user uploads "flowers.jpg" to /files/photos/12345/ then the file must be copied over FTP to C:\content\photos\12345
So far I have this bash script, it does copy the files to server B, but all files are placed in C:\content, and not in the corresponding subfolders. Who can help me find the correct syntax?
#!/bin/bash
cd /files
inotifywait -q -r -m -e close_write,moved_to . --format %w%f |
while read FILE; do
lftp -e "put $FILE; exit" -u user,password -p 2121 ftp.server-a.com
done