rsync from within Java

One thing that I have been missing lately was a nice Java library that provides rsync-like functionality. But I didn’t really find anything suitable, so I decided to write a Java wrapper for it myself, trying to make it as easy as possible to integrate rsync into Java applications.

The wrapper approach wasn’t an issue for Linux and Mac OSX, as these operating systems already have native rsync binaries. The problem, like most of the times, is Windows. My solution for this was to use the binaries from a 64-bit version of cygwin. Only rsync and ssh are required as binaries to perform synchronization. For Windows, that required a few more DLLs, unfortunately. In the end, I decided to set up a little mini-cygwin with just ssh and rsync in the user’s home directory (%USERPROFILE%\rsync4j). This approach also allows the storage of public key pairs in %USERPROFILE%\rsync4j\home\%USERNAME%\.ssh, making it easier for password-less synchronization.

Here is the project homepage:

https://github.com/fracpete/rsync4j

Early stages, so bugs are to be expected. 😉

4 Comments

  1. Arun Sundaram

    Awesome project filling a niche need.
    A question: is there a way to read the output of the rsync process ‘as it writes them to std out/err’ using ConsoleOutputProcessOutput?
    What I am trying to do is to provide a visual output to the user as rsync runs –since it is quite long running in my case.

    Thanks for the contribution.

    Reply
    1. fracpete (Post author)

      rsync4j uses my processoutput4j library (https://github.com/fracpete/processoutput4j) for processing the stderr/stdout output. You can use the “com.github.fracpete.processoutput4j.output.StreamingProcessOutput” scheme instead and supply an object that implements the “com.github.fracpete.processoutput4j.core.StreamingProcessOwner” interface to handle the output yourself.

      Reply
      1. fracpete (Post author)

        Just added examples to the README.md of the processoutput4j and rsync4j projects for the StreamingProcessOutput class.

        Reply
        1. Arun Sundaram

          I was able to use your example and get rsync’s progress out to the GUI as text. Works like a CHARM.

          I will subclass StreamingProcessOwner to interpret processOutput()’s line to make it easy for the GUI to show the percentage of progress in a widget.

          Reply

Leave a Comment

Your email address will not be published. Required fields are marked *