10

I come primarily from a Windows background, migrating over to Mac. I've used WinSCP and loved a featured called "Keep Remote Directory Up To Date".

Here's the question: is there an equivalent SCP client for OSX that will monitor a directory for changes and upload when detected? I don't care if it's a GUI client or via command-line (rsync, ssh, etc).

0

Your best bet is probably to use Folder Actions and adapting the new item alert script to your needs, issuing a call to the command line utility of your choice.

9
alias run_rsync='rsync -azP --exclude ".*/" --exclude ".*" --exclude "tmp/" /source_folder username@host:/destination_folder'
run_rsync; fswatch -o . | while read f; do run_rsync; done

Second line runs run_rsync once unconditionally and then - on each change in current directory (or specify exact path instead of .)

You will need fswatch - here is how to install via brew:

brew install fswatch

Rsync options:

  • -a - stands for "archive" and syncs recursively and preserves symbolic links, special and device files, modification times, group, owner, and permissions.
  • -z - compression
  • -P - combines the flags --progress and --partial. The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers
  • --exclude - excludes files by pattern
  • You had me really confused for a while because sync is a system utility (at least on every *nix I've seen; not sure about OSX, but see no reaosn why it wouldn't be there). You may want to give your snipped a different name. Also, this doesn't go over SSH, which the OP wanted; simply passing -e ssh to rsync should fix that. – a CVn Aug 17 '16 at 12:56
  • @MichaelKjörling :+1: fixed, thank you for notice! – Daniel Aug 17 '16 at 14:33
  • I don't understand your exclusions, could you explain those? – peedee Jul 16 at 8:00
1

You may use launchd instead of folder actions (to get some sample code just google for: launchd folder watcher).

You may then combine you launchd folder watcher item with a scp script similar to this one.

Or, use rsync over ssh like so:

rsync -urltv --delete -e ssh /path/to/dir othermachine:/path/to/dir

For a commercial cross-platform software solution see GoodSync.

0

Check out Transmit by Panic. From one of their blog posts, a commenter said:

One of my favorite features, that some people may not know, when you open a document into a certain application in Transmit (let’s say an .html file into BBEdit) then edit the document and Save it; Transmit automatically uploads it back to the server to the same file, no questions asked. It works wonders when making websites and editing CSS. Also convenient to make small corrections in images through Photoshop. You can also handle how Transmit deals with certain file extensions through the Prefs.

  • I've looked into Transmit - unfortunately it doesn't support SCP - only SFTP connections. Also, Transmit refuses to open my private key files. – pygorex1 Jan 12 '11 at 2:24
  • This feature is something different. It just means you can directly edit files from the remote server using the editor of your choice. Other FTP programs also support this. – Daniel Beck Jan 12 '11 at 5:38
0

I have come across a ruby script that does what you need, but it will take a little adapting.

Description:
rsync whenever the directory the script is in changes using the OS X FSEvents API https://gist.github.com/149491

0

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).

  1. I created the key to Passwordless Login using this tutorial from Dreamhost wiki: http://cl.ly/MIw5

    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:

    ssh username@host.com You should login without passwords being asked :P

  2. I installed the Terminal Notifier from the Github page: http://cl.ly/MJ5x

    2.1. I used the Gem installer command. In Terminal, type:

    gem install terminal-notifier

    2.3. Test if the notification works.In Terminal, type:

    terminal-notifier -message "Starting sync"

  3. 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 ~/Scripts/sync.sh I used the ".sh extension, but I don't know if its needed.

    #!/bin/bash terminal-notifier -message "Starting sync" rsync -azP ~/Sites/folder/ user@host.com:site_folder/ terminal-notifier -message "Sync has finished"

    3.1. Remember to give execution permission to this sh script. In Terminal, type:

    sudo chmod 777 ~/Scripts/sync.sh 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.

  4. Finally, I downloaded and installed Watchdog from the Github page: http://cl.ly/MJfb

    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:

    brew install libyaml

    4.2. Then, I used the "easy_install command". Go the folder of Watchdog, and type in Terminal:

    easy_install watchdog

  5. Now, everything is installed! Go the folder you want to be synced, change this code to your needs, and type in Terminal:

      watchmedo shell-command
          --patterns="*.php;*.txt;*.js;*.css" \
          --recursive \
          --command='~/Scripts/Sync.sh' \
          .
    

    It has to be EXACTLY 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.

    I tried without the line breaks, and it doesn't work!

    In my Mac, I always get an error, but it doesn't seem to affect anything:

    /Library/Python/2.7/site-packages/argh-0.22.0-py2.7.egg/argh/completion.py:84: UserWarning: Bash completion not available. Install argcomplete.

    Now, made some changes in a file inside the folder, and watch the magic!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.