To synchronize files in real-time between two servers, there are several solutions you can consider:

  1. rsync with inotifywait:
    Use rsync in combination with inotifywait. inotifywait monitors file system changes on server A, and every time a change is detected, rsync synchronizes the files with server B. This method is very efficient for almost real-time synchronization.

    Example script:

    #!/bin/bash
    SRC="/path/to/sync"
    DEST="user@serverB:/destination/path"
    inotifywait -m -r -e modify,create,delete $SRC | while read path action file; do
    rsync -avz $SRC $DEST
    done
  2. Lsyncd:
    Lsyncd (Live Syncing Daemon) is a more advanced tool that uses rsync for synchronization and inotify to monitor changes in real-time. It is easy to configure and runs as a background daemon.
  3. lftp:
    Although lftp is not specifically a real-time synchronization tool, you can use it for frequent syncs using its mirror command with the --continue option to synchronize directories between servers A and B. However, this is not a real-time solution but requires periodic execution.

    Example of lftp usage:

    lftp -e "mirror --reverse --delete --continue --verbose /local/directory /remote/directory; bye" -u user,password serverB

    Note: While lftp can be useful, it doesn’t provide real-time synchronization. For that, rsync with inotifywait or Lsyncd are better options.