Keep Remote Directory Up-to-date

后端 未结 17 1712
一向
一向 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:25

    Will DropBox (http://www.getdropbox.com/) do what you want?

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-30 07:28

    If you are developing python on remote server, Pycharm may be a good choice to you. You can synchronize your remote files with your local files utilizing pycharm remote development feature. The guide link as: https://www.jetbrains.com/help/pycharm/creating-a-remote-server-configuration.html

    0 讨论(0)
  • 2021-01-30 07:28

    Great question I have searched answer for hours !

    I have tested lsyncd and the problem is that the default delay is far too long and no example command line give the -delay option.

    Other problem is that by default rsync ask password each time !

    Solution with lsyncd :

    lsyncd --nodaemon -rsyncssh local_dir remote_user@remote_host remote_dir -delay .2
    

    other way is to use inotify-wait in a script :

    while inotifywait -r -e modify,create,delete local_dir ; do
        # if you need you can add wait here
        rsync -avz local_dir remote_user@remote_host:remote_dir
    done
    

    For this second solution you will have to install inotify-tools package

    To suppress the need to enter password at each change, simply use ssh-keygen : https://superuser.com/a/555800/510714

    0 讨论(0)
  • 2021-01-30 07:30

    To detect changed files, you could try fam (file alteration monitor) or inotify. The latter is linux-specific, fam has a bsd port which might work on OS X. Both have userspace tools that could be used in a script together with rsync.

    0 讨论(0)
  • 2021-01-30 07:31

    What you want to do for linux remote access is use 'sshfs' - the SSH File System.

    # sshfs username@host:path/to/directory local_dir
    

    Then treat it like an network mount, which it is...

    A bit more detail, like how to set it up so you can do this as a regular user, on my blog

    If you want the asynchronous behavior of winSCP, you'll want to use rsync combined with something that executes it periodically. The cron solution above works, but may be overkill for the winscp use case.

    The following command will execute rsync every 5 seconds to push content to the remote host. You can adjust the sleep time as needed to reduce server load.

    # while true; do rsync -avrz localdir user@host:path; sleep 5; done
    

    If you have a very large directory structure and need to reduce the overhead of the polling, you can use 'find':

    # touch -d 01/01/1970 last; while true; do if [ "`find localdir -newer last -print -quit`" ]; then touch last; rsync -avrz localdir user@host:path; else echo -ne .; fi; sleep 5; done
    

    And I said cron may be overkill? But at least this is all just done from the command line, and can be stopped via a ctrl-C.

    kb

    0 讨论(0)
提交回复
热议问题