Use inotifywait and lftp to synchronize servers

Posted by KBoek on Server Fault See other posts from Server Fault or by KBoek
Published on 2014-06-02T12:04:24Z Indexed on 2014/06/03 9:27 UTC
Read the original article Hit count: 339

Filed under:
|
|
|

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

© Server Fault or respective owner

Related posts about linux

Related posts about bash