Keep Remote Directory Up-to-date

后端 未结 17 1740
一向
一向 2021-01-30 06:39

I absolutely love the Keep Remote Directory Up-to-date feature in Winscp. Unfortunately, I can\'t find anything as simple to use in OS X or Linux. I know the same thing can

17条回答
  •  臣服心动
    2021-01-30 07:27

    I have the same issue. I loved winscp "keep remote directory up to date" command. However, in my quest to rid myself of Windows, I lost winscp. I did write a script that uses fileschanged and rsync to do something similar much closer to real time.

    How to use:

    • Make sure you have fileschanged installed
    • Save this script in /usr/local/bin/livesync or somewhere reachable in your $PATH and make it executable
    • Use Nautilus to connect to the remote host (sftp or ftp)
    • Run this script by doing livesync SOURCE DEST
    • The DEST directory will be in /home/[username]/.gvfs/[path to ftp scp or whatever]

    A Couple downsides:

    • It is slower than winscp (my guess is because it goes through Nautilus and has to detect changes through rsync as well)
    • You have to manually create the destination directory if it doesn't already exist. So if you're adding a directory, it won't detect and create the directory on the DEST side.
    • Probably more that I haven't noticed yet
    • Also, do not attempt to synchronize a SRC directory named "rsyncThis". That will probably not be good :)

    #!/bin/sh
    
    upload_files()
    {
        if [ "$HOMEDIR" = "." ]
        then
            HOMEDIR=`pwd`
        fi
    
        while read  input
        do
            SYNCFILE=${input#$HOMEDIR}
            echo -n "Sync File: $SYNCFILE..."
            rsync -Cvz --temp-dir="$REMOTEDIR" "$HOMEDIR/$SYNCFILE" "$REMOTEDIR/$SYNCFILE" > /dev/null
            echo "Done."
        done
    }
    
    
    help()
    {
        echo "Live rsync copy from one directory to another.  This will overwrite the existing files on DEST."
        echo "Usage: $0 SOURCE DEST"    
    }
    
    
    case "$1" in
      rsyncThis)
        HOMEDIR=$2
        REMOTEDIR=$3
        echo "HOMEDIR=$HOMEDIR"
        echo "REMOTEDIR=$REMOTEDIR"
        upload_files
        ;;
    
      help)
        help
        ;;
    
      *)
        if [ -n "$1" ] && [ -n "$2" ]
        then
            fileschanged -r "$1" | "$0" rsyncThis "$1" "$2"
        else
            help
        fi
        ;;
    esac
    

提交回复
热议问题