<p>I absolutely love the <a href="http://winscp.net/eng/docs/task_keep_up_to_date" rel="noreferrer">Keep Remote Directory Up-to-date</a> feature in <a href="http://winscp.net/" rel="noreferrer">Winscp</a>. Unfortunately, I can't find anything as simple to use in OS X or Linux. I know the same thing can <em>theoretically</em> be accomplished using <a href="http://freshmeat.net/projects/changedfiles/" rel="noreferrer">changedfiles</a> or <a href="http://samba.anu.edu.au/rsync/" rel="noreferrer">rsync</a>, but I've always found the tutorials for both tools to be lacking and/or contradictory. </p>

<p>I basically just need a tool that works in OSX or Linux and keeps a remote directory in sync (mirrored) with a local directory while I make changes to the local directory.</p>

<hr>

<p><strong>Update</strong></p>

<p>Looking through the solutions, I see a couple which solve the general problem of keeping a remote directory in sync with a local directory <em>manually</em>. I know that I can set a cron task to run rsync every minute, and this should be fairly close to real time. </p>

<p>This is not the exact solution I was looking for as winscp does this and more: it detects file changes in a directory (while I work on them) and then automatically pushes the changes to the remote server. I know this is not the best solution (no code repository), but it allows me to very quickly test code on a server while I develop it. Does anyone know how to combine rsync with any other commands to get this functionality?</p>

[{'answer_id': 9287, 'author': 'dwj', 'author_id': 346, 'author_profile': 'https://Stackoverflow.com/users/346', 'pm_score': 5, 'selected': True, 'text': '<p>How "real-time" do you want the syncing? I would still lean toward rsync since you know it is going to be fully supported on both platforms (Windows, too, with cygwin) and you can run it via a cron job. I have a super-simple bash file that I run on my system (this does <em>not</em> remove old files):</p>\n\n<pre><code>#!/bin/sh\nrsync -avrz --progress --exclude-from .rsync_exclude_remote . remote_login@remote_computer:remote_dir    \n\n# options\n#   -a  archive\n#   -v  verbose\n#   -r  recursive\n#   -z  compress \n</code></pre>\n\n<p>Your best bet is to set it up and try it out.  The <code>-n (--dry-run)</code> option is your friend!</p>\n\n<p>Keep in mind that rsync (at least in cygwin) does not support unicode file names (as of 16 Aug 2008).</p>\n'}, {'answer_id': 9288, 'author': 'icco', 'author_id': 1063, 'author_profile': 'https://Stackoverflow.com/users/1063', 'pm_score': 2, 'selected': False, 'text': '<p>You could always use version control, like SVN, so all you have to do is have the server run svn up on a folder every night. This runs into security issues if you are sharing your files publicly, but it works. </p>\n\n<p>If you are using Linux though, learn to use rsync. It\'s really not that difficult as you can test every command with -n. Go through the <a href="http://www.samba.org/ftp/rsync/rsync.html" rel="nofollow noreferrer">man page</a>, the basic format you will want is </p>\n\n<blockquote>\n  <p>rsync [OPTION...] SRC... [USER@]HOST:DEST</p>\n</blockquote>\n\n<p>the command I run from my school server to my home backup machine is this</p>\n\n<blockquote>\n  <p>rsync -avi --delete ~ me@homeserv:~/School/ >> BackupLog.txt</p>\n</blockquote>\n\n<p>This takes all of the files in my home directory (~) and uses rsync\'s archive mode (-a), verbosly (-v), lists all of the changes made (-i), while deleting any files that don\'t exist anymore (--delete) and puts the in the Folder /home/me/School/ on my remote server. All of the information it prints out (what was copied, what was deleted, etc.) is also appended to the file BackupLog.txt</p>\n\n<p>I know that\'s a whirlwind tour of rsync, but I hope it helps. </p>\n'}, {'answer_id': 9302, 'author': 'Pat Notz', 'author_id': 825, 'author_profile': 'https://Stackoverflow.com/users/825', 'pm_score': 2, 'selected': False, 'text': '<p>The <code>rsync</code> solutions are really good, especially if you\'re only pushing changes one way.  Another great tool is <code>unison</code> -- it attempts to syncronize changes in both directions.  Read more at <a href="http://www.cis.upenn.edu/~bcpierce/unison/" rel="nofollow noreferrer" title="Unison Home Page">the Unison homepage</a>.</p>\n'}, {'answer_id': 9346, 'author': 'Marie Fischer', 'author_id': 719, 'author_profile': 'https://Stackoverflow.com/users/719', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 9353, 'author': 'stimms', 'author_id': 361, 'author_profile': 'https://Stackoverflow.com/users/361', 'pm_score': 1, 'selected': False, 'text': '<p>It seems like perhaps you\'re solving the wrong problem.  If you\'re trying to edit files on a remote computer then you might try using something like the ftp plugin for jedit.  <a href="http://plugins.jedit.org/plugins/?FTP" rel="nofollow noreferrer">http://plugins.jedit.org/plugins/?FTP</a>  This ensures that you have only one version of the file so it can\'t ever be out of sync.</p>\n'}, {'answer_id': 14718, 'author': 'Matthew Schinckel', 'author_id': 188, 'author_profile': 'https://Stackoverflow.com/users/188', 'pm_score': 0, 'selected': False, 'text': "<p>You can also use Fetch as an SFTP client, and then edit files directly on the server from within that.  There are also SSHFS (mount an ssh folder as a Volume) options.  This is in line with what stimms said - are you sure you want stuff kept in sync, or just want to edit files on the server?</p>\n\n<p>OS X has it's own file notifications system - this is what Spotlight is based upon.  I haven't heard of any program that uses this to then keep things in sync, but it's certainly conceivable.</p>\n\n<p>I personally use RCS for this type of thing:- whilst it's got a manual aspect, it's unlikely I want to push something to even the test server from my dev machine without testing it first.  And if I am working on a development server, then I use one of the options given above.</p>\n"}, {'answer_id': 73415, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 1, 'selected': False, 'text': "<p>Building off of icco's suggestion of SVN, I'd actually suggest that if you are using subversion or similar for source control (and if you aren't, you should probably start) you can keep the production environment up to date by putting the command to update the repository into the post-commit hook.</p>\n\n<p>There are a lot of variables in how you'd want to do that, but what I've seen work is have the development or live site be a working copy and then have the post-commit use an ssh key with a forced command to log into the remote site and trigger an svn up on the working copy.  Alternatively in the post-commit hook you could trigger an svn export on the remote machine, or a local (to the svn repository) svn export and then an rsync to the remote machine.</p>\n\n<p>I would be worried about things that detect changes and push them, and I'd even be worried about things that ran every minute, just because of race conditions.  How do you know it's    not going to transfer the file at the very same instant it's being written to?  Stumble across that once or twice and you'll lose all of the time-saving advantage you had by constantly rsyncing or similar.</p>\n"}, {'answer_id': 112881, 'author': 'Scott', 'author_id': 7399, 'author_profile': 'https://Stackoverflow.com/users/7399', 'pm_score': 1, 'selected': False, 'text': '<p>Will DropBox (<a href="http://www.getdropbox.com/" rel="nofollow noreferrer">http://www.getdropbox.com/</a>) do what you want?</p>\n'}, {'answer_id': 289305, 'author': 'KevinButler', 'author_id': 34463, 'author_profile': 'https://Stackoverflow.com/users/34463', 'pm_score': 3, 'selected': False, 'text': '<p>What you want to do for linux remote access is use \'sshfs\' - the SSH File System.</p>\n\n<pre><code># sshfs username@host:path/to/directory local_dir\n</code></pre>\n\n<p>Then treat it like an network mount, which it is...</p>\n\n<p>A bit more detail, like how to set it up so you can do this as a regular user, on <a href="http://soi.kd6.us/2008/11/05/so-i-used-sshfs-to-mount-a-remote-filesystem/" rel="noreferrer">my blog</a></p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<pre><code># while true; do rsync -avrz localdir user@host:path; sleep 5; done\n</code></pre>\n\n<p>If you have a very large directory structure and need to reduce the overhead of the polling, you can use \'find\':</p>\n\n<pre><code># 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\n</code></pre>\n\n<p>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. </p>\n\n<p>kb</p>\n'}, {'answer_id': 4378901, 'author': 'webasdf', 'author_id': 228301, 'author_profile': 'https://Stackoverflow.com/users/228301', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>How to use:</p>\n\n<ul>\n<li>Make sure you have fileschanged installed</li>\n<li>Save this script in /usr/local/bin/livesync or somewhere reachable in your $PATH and make it executable</li>\n<li>Use Nautilus to connect to the remote host (sftp or ftp)</li>\n<li>Run this script by doing livesync <strong>SOURCE DEST</strong></li>\n<li>The DEST directory will be in /home/[username]/.gvfs/[path to ftp scp or whatever]</li>\n</ul>\n\n<p>A Couple downsides:</p>\n\n<ul>\n<li>It is slower than winscp (my guess is because it goes through Nautilus and has to detect changes through rsync as well)</li>\n<li>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.</li>\n<li>Probably more that I haven\'t noticed yet</li>\n<li>Also, do not attempt to synchronize a SRC directory named "rsyncThis".  That will probably not be good :)</li>\n</ul>\n\n<hr>\n\n\n\n<pre class="lang-sh prettyprint-override"><code>#!/bin/sh\n\nupload_files()\n{\n    if [ "$HOMEDIR" = "." ]\n    then\n        HOMEDIR=`pwd`\n    fi\n\n    while read  input\n    do\n        SYNCFILE=${input#$HOMEDIR}\n        echo -n "Sync File: $SYNCFILE..."\n        rsync -Cvz --temp-dir="$REMOTEDIR" "$HOMEDIR/$SYNCFILE" "$REMOTEDIR/$SYNCFILE" &gt; /dev/null\n        echo "Done."\n    done\n}\n\n\nhelp()\n{\n    echo "Live rsync copy from one directory to another.  This will overwrite the existing files on DEST."\n    echo "Usage: $0 SOURCE DEST"    \n}\n\n\ncase "$1" in\n  rsyncThis)\n    HOMEDIR=$2\n    REMOTEDIR=$3\n    echo "HOMEDIR=$HOMEDIR"\n    echo "REMOTEDIR=$REMOTEDIR"\n    upload_files\n    ;;\n\n  help)\n    help\n    ;;\n\n  *)\n    if [ -n "$1" ] &amp;&amp; [ -n "$2" ]\n    then\n        fileschanged -r "$1" | "$0" rsyncThis "$1" "$2"\n    else\n        help\n    fi\n    ;;\nesac\n</code></pre>\n'}, {'answer_id': 8854595, 'author': 'iPatch', 'author_id': 1148185, 'author_profile': 'https://Stackoverflow.com/users/1148185', 'pm_score': 1, 'selected': False, 'text': '<p>I used to have the same setup under Windows as you, that is a local filetree (versioned) and a test environment on a remote server, which I kept mirrored in realtime with WinSCP. When I switched to Mac I had to do quite some digging before I was happy, but finally ended up using:</p>\n<ul>\n<li><a href="https://www.smartsvn.com/" rel="nofollow noreferrer">SmartSVN</a> as my subversion client</li>\n<li><a href="http://www.sublimetext.com/2" rel="nofollow noreferrer">Sublime Text 2</a> as my editor (already used it on Windows)</li>\n<li>SFTP-plugin to ST2 which handles the uploading on save (sorry, can\'t post more than 2 links)</li>\n</ul>\n<p>I can really recommend this setup, hope it helps!</p>\n'}, {'answer_id': 14435664, 'author': 'Eduardo Russo', 'author_id': 1302318, 'author_profile': 'https://Stackoverflow.com/users/1302318', 'pm_score': 0, 'selected': False, 'text': '<p>Well, I had the same kind of problem and it is possible using these together: rsync, SSH Passwordless Login, Watchdog (a Python sync utility) and Terminal Notifier (an OS X notification utility made with Ruby. Not needed, but helps to know when the sync has finished).</p>\n\n<ol>\n<li><p>I created the key to Passwordless Login using this tutorial from Dreamhost wiki: <a href="http://cl.ly/MIw5" rel="nofollow">http://cl.ly/MIw5</a></p>\n\n<p>1.1. When you finish, test if everything is ok… if you can\'t Passwordless Login, maybe you have to try afp mount. Dreamhost (where my site is) does not allow afp mount, but allows Passwordless Login. In terminal, type:</p>\n\n<p><code>ssh username@host.com\n</code>\n  You should login without passwords being asked :P</p></li>\n<li><p>I installed the Terminal Notifier from the Github page: <a href="http://cl.ly/MJ5x" rel="nofollow">http://cl.ly/MJ5x</a></p>\n\n<p>2.1. I used the Gem installer command. In Terminal, type:</p>\n\n<p><code>gem install terminal-notifier\n</code></p>\n\n<p>2.3. Test if the notification works.In Terminal, type:</p>\n\n<p><code>terminal-notifier -message "Starting sync"\n</code></p></li>\n<li><p>Create a sh script to test the rsync + notification. Save it anywhere you like, with the name you like. In this example, I\'ll call it <strong>~/Scripts/sync.sh</strong> I used the ".sh  extension, but I don\'t know if its needed.</p>\n\n<p><code>#!/bin/bash\nterminal-notifier -message "Starting sync"\nrsync -azP ~/Sites/folder/ user@host.com:site_folder/\nterminal-notifier -message "Sync has finished"\n</code></p>\n\n<p>3.1. Remember to give execution permission to this sh script. In Terminal, type:</p>\n\n<p><code>sudo chmod 777 ~/Scripts/sync.sh\n</code>\n 3.2. Run the script and verify  if the messages are displayed correctly and the rsync actually sync your local folder with the remote folder.</p></li>\n<li><p>Finally, I downloaded and installed Watchdog from the Github page: <a href="http://cl.ly/MJfb" rel="nofollow">http://cl.ly/MJfb</a></p>\n\n<p>4.1. First, I installed the libyaml dependency using Brew (there are lot\'s of help how to install Brew - like an "aptitude" for OS X). In Terminal, type:</p>\n\n<p><code>brew install libyaml\n</code></p>\n\n<p>4.2. Then, I used the "easy_install command". Go the folder of Watchdog, and type in Terminal:</p>\n\n<p><code>easy_install watchdog\n</code></p></li>\n<li><p>Now, everything is installed! <strong>Go the folder you want to be synced</strong>, <strong>change this code to your needs</strong>, and type in Terminal:</p>\n\n<pre><code>  watchmedo shell-command\n      --patterns="*.php;*.txt;*.js;*.css" \\\n      --recursive \\\n      --command=\'~/Scripts/Sync.sh\' \\\n      .\n</code></pre>\n\n<p>It has to be <strong>EXACTLY</strong> this way, with the slashes and line breaks, so you\'ll have to copy these lines to a text editor, change the script, paste in terminal and press return.</p>\n\n<p>I tried without the line breaks, and it doesn\'t work!</p>\n\n<p>In my Mac, I always get an error, but it doesn\'t seem to affect anything:</p>\n\n<p><code>/Library/Python/2.7/site-packages/argh-0.22.0-py2.7.egg/argh/completion.py:84: UserWarning: Bash completion not available. Install argcomplete.\n</code></p>\n\n<p>Now, made some changes in a file inside the folder, and watch the magic!</p></li>\n</ol>\n'}, {'answer_id': 15283061, 'author': 'juwens', 'author_id': 534812, 'author_profile': 'https://Stackoverflow.com/users/534812', 'pm_score': 5, 'selected': False, 'text': '<p><a href="https://github.com/axkibe/lsyncd#readme" rel="noreferrer">lsyncd</a> seems to be the perfect solution. it combines <strong>inotify</strong> (kernel builtin function which watches for file changes in a directory trees) and <strong>rsync</strong> (cross platform file-syncing-tool). </p>\n\n<pre><code>lsyncd -rsyncssh /home remotehost.org backup-home/\n</code></pre>\n\n<p>Quote from github:</p>\n\n<blockquote>\n  <p>Lsyncd watches a local directory trees event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds and then spawns one (or more) process(es) to synchronize the changes. By default this is rsync. Lsyncd is thus a light-weight live mirror solution that is comparatively easy to install not requiring new filesystems or blockdevices and does not hamper local filesystem performance. </p>\n</blockquote>\n'}, {'answer_id': 24455670, 'author': 'Mike Mitterer', 'author_id': 504184, 'author_profile': 'https://Stackoverflow.com/users/504184', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m using this little Ruby-Script:</p>\n\n<pre class="lang-ruby prettyprint-override"><code>#!/usr/bin/env ruby\n#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n# Rsyncs 2Folders\n#\n# watchAndSync by Mike Mitterer, 2014 &lt;http://www.MikeMitterer.at&gt;\n# with credit to Brett Terpstra &lt;http://brettterpstra.com&gt;\n# and Carlo Zottmann &lt;https://github.com/carlo/haml-sass-file-watcher&gt;\n# Found link on: http://brettterpstra.com/2011/03/07/watch-for-file-changes-and-refresh-your-browser-automatically/\n#\n\ntrap("SIGINT") { exit }\n\nif ARGV.length &lt; 2\n  puts "Usage: #{$0} watch_folder sync_folder"\n  puts "Example: #{$0} web keepInSync"\n  exit\nend\n\ndev_extension = \'dev\'\nfiletypes = [\'css\',\'html\',\'htm\',\'less\',\'js\', \'dart\']\n\nwatch_folder = ARGV[0]\nsync_folder = ARGV[1]\n\nputs "Watching #{watch_folder} and subfolders for changes in project files..."\nputs "Syncing with #{sync_folder}..."\n\nwhile true do\n  files = []\n  filetypes.each {|type|\n    files += Dir.glob( File.join( watch_folder, "**", "*.#{type}" ) )\n  }\n  new_hash = files.collect {|f| [ f, File.stat(f).mtime.to_i ] }\n  hash ||= new_hash\n  diff_hash = new_hash - hash\n\n  unless diff_hash.empty?\n    hash = new_hash\n\n    diff_hash.each do |df|\n      puts "Detected change in #{df[0]}, syncing..."\n      system("rsync -avzh #{watch_folder} #{sync_folder}")\n    end\n  end\n\n  sleep 1\nend\n</code></pre>\n\n<p>Adapt it for your needs!</p>\n'}, {'answer_id': 28635944, 'author': 'k2k2e6', 'author_id': 2138554, 'author_profile': 'https://Stackoverflow.com/users/2138554', 'pm_score': 1, 'selected': False, 'text': '<p>User watcher.py and rsync to automate this. Read the following step by step instructions here:</p>\n\n<p><a href="http://kushellig.de/linux-file-auto-sync-directories/" rel="nofollow">http://kushellig.de/linux-file-auto-sync-directories/</a></p>\n'}, {'answer_id': 56051542, 'author': 'deserve', 'author_id': 11473221, 'author_profile': 'https://Stackoverflow.com/users/11473221', 'pm_score': 0, 'selected': False, 'text': '<p>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:\n<a href="https://www.jetbrains.com/help/pycharm/creating-a-remote-server-configuration.html" rel="nofollow noreferrer">https://www.jetbrains.com/help/pycharm/creating-a-remote-server-configuration.html</a></p>\n'}, {'answer_id': 56717832, 'author': 'doom', 'author_id': 1619521, 'author_profile': 'https://Stackoverflow.com/users/1619521', 'pm_score': 2, 'selected': False, 'text': '<p>Great question I have searched answer for hours !</p>\n\n<p>I have tested <a href="https://github.com/axkibe/lsyncd" rel="nofollow noreferrer">lsyncd</a> and the problem is that the <strong>default delay is far too long</strong> and no example command line give the <code>-delay</code> option.</p>\n\n<p>Other problem is that by default rsync ask <strong>password</strong> each time !</p>\n\n<p>Solution with <strong>lsyncd</strong> :</p>\n\n<pre><code>lsyncd --nodaemon -rsyncssh local_dir remote_user@remote_host remote_dir -delay .2\n</code></pre>\n\n<p>other way is to use <strong>inotify-wait</strong> in a script :</p>\n\n<pre><code>while inotifywait -r -e modify,create,delete local_dir ; do\n    # if you need you can add wait here\n    rsync -avz local_dir remote_user@remote_host:remote_dir\ndone\n</code></pre>\n\n<p>For this second solution you will have to install <code>inotify-tools</code> package</p>\n\n<p>To <strong>suppress the need</strong> to enter password at each change, simply use <code>ssh-keygen</code> :\n<a href="https://superuser.com/a/555800/510714">https://superuser.com/a/555800/510714</a></p>\n'}]
['https://Stackoverflow.com/questions/9279', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/302/']