### Rsync Daemon Upload Example
Source: https://fracpete.github.io/rsync4j/java
Demonstrates uploading a directory to an rsync daemon. Ensure the rsync daemon is configured and running on the server, and the destination URL is correctly specified.
```java
import com.github.fracpete.rsync4j.RSync;
import com.github.fracpete.processoutput4j.output.ConsoleOutputProcessOutput;
...
RSync rsync = new RSync()
.recursive(true)
.times(true)
.dirs(true)
.verbose(true)
.source("/home/myuser/some/where")
.destination("rsync://192.168.1.100:12000/files/");
ConsoleOutputProcessOutput output = new ConsoleOutputProcessOutput();
output.monitor(rsync.builder());
```
--------------------------------
### Add rsync4j Core for Linux/Mac
Source: https://fracpete.github.io/rsync4j/maven
Use this dependency for Linux and Mac systems. It requires that rsync and ssh binaries are already installed locally.
```xml
com.github.fracpete
rsync4j-core
3.3.0-7
```
--------------------------------
### Set File Permissions with rsync4j on Windows
Source: https://fracpete.github.io/rsync4j/faq
When encountering incorrect file permissions on Windows, use the `chmod` method of the `RSync` class to set appropriate permissions. The example `ugo=rwX` grants read, write, and execute permissions to owner, group, and others, with execute only for directories.
```java
.chmod("ugo=rwX")
```
--------------------------------
### Windows Path to Cygwin Path Conversion
Source: https://fracpete.github.io/rsync4j/windows
Local Windows paths are automatically converted to Cygwin notation for use with rsync4j. For example, a Windows path like C:\\some\\path\\blah.txt becomes /cygdrive/c/some/path/blah.txt.
```text
C:\\some\\path\\blah.txt
```
```text
/cygdrive/c/some/path/blah.txt
```
--------------------------------
### RSync4j Help Screen
Source: https://fracpete.github.io/rsync4j/commandline
Displays the usage and all available options for the RSync4j command-line tool. This is useful for understanding the full range of configurable parameters.
```bash
usage: com.github.fracpete.rsync4j.RSync
[-h] [--output-commandline] [--maxtime MAXTIME] [-v]
[--info INFO] [--debug DEBUG] [--msgs2stderr] [-q] [--no-motd] [-c]
[-a] [-r] [-R] [--no-implied-dirs] [-b] [--backup-dir BACKUPDIR]
[--suffix SUFFIX] [-u] [--inplace] [--append] [--append-verify] [-d]
[-l] [-L] [--copy-unsafe-links] [--safe-links] [--munge-links] [-k]
[-K] [-H] [-p] [-E] [--chmod CHMOD] [-X] [-o] [-g] [--devices]
[--specials] [-t] [-O] [-J] [--super] [--fake-super] [-S]
[--preallocate] [-n] [-W] [-x] [-B BLOCKSIZE]
[-e RSH] [--rsync-path RSYNCPATH] [--existing] [--ignore-existing]
[--remove-source-files] [--delete] [--delete-before]
[--delete-during] [--delete-delay] [--delete-after]
[--delete-excluded] [--ignore-missing-args] [--delete-missing-args]
[--ignore-errors] [--force] [--max-delete MAXDELETE]
[--max-size MAXSIZE] [--min-size MINSIZE] [--partial]
[--partial-dir PARTIALDIR] [--delay-updates] [-m] [--numeric-ids]
[--usermap USERMAP] [--groupmap GROUPMAP] [--chown CHOWN]
[--timeout TIMEOUT] [--contimeout CONTIMEOUT] [-I] [-M REMOTEOPTION]
[--size-only] [--modify-window MODIFYWINDOW] [-T TEMPDIR] [-y]
[--compare-dest COMPAREDEST] [--copy-dest COPYDEST]
[--link-dest LINKDEST] [-z] [--compress-level COMPRESSLEVEL]
[--skip-compress SKIPCOMPRESS] [-C] [-f FILTER] [--exclude EXCLUDE]
[--exclude-from EXCLUDEFROM] [--include INCLUDE]
[--include-from INCLUDEFROM] [--files-from FILESFROM] [-0] [-s]
[--address ADDRESS] [--port PORT] [--sockopts SOCKOPTS]
[--blocking-io] [--stats] [-8] [--human-readable] [--progress] [-i]
[--out-format OUTFORMAT] [--log-file LOGFILE]
[--log-file-format LOGFILEFORMAT] [--password-file PASSWORDFILE]
[--list-only] [--bwlimit BWLIMIT] [--outbuf OUTBUF]
[--write-batch WRITEBATCH] [--only-write-batch ONLYWRITEBATCH]
[--read-batch READBATCH] [--protocol PROTOCOL] [--iconv ICONV]
[--checkum-seed CHECKSUMSEED] [-4] [-6] [--version]
[--checksum-choice CHECKSUMCHOICE] [-U] [--open-noatime]
[--write-devices] [--copy-as COPYAS] [--early-input EARLYINPUT]
[--max-alloc MAXALLOC] [--mkpath] [-N] [--stop-at STOPAT]
[--stop-after STOPAFTER] [--copy-devices] [--fsync] [--trust-sender]
[--additional ADDITIONAL]
[source(s)/destination [source(s)/destination ...]]
```
--------------------------------
### Rsync with Windows Path and Identity
Source: https://fracpete.github.io/rsync4j/java
Demonstrates how to configure rsync on Windows when using the `rsh` option with an identity file. It utilizes `Binaries.sshBinary()` and `Binaries.convertPath()` for correct path construction.
```java
RSync rsync = new RSync()
.source("C:\\somedir")
.destination("D:\\otherdir")
.recursive(true)
.rsh(Binaries.sshBinary() + " -i " + Binaries.convertPath("C:\\keys\\mykey.pub"));
```
--------------------------------
### SshKeyGen Help Screen
Source: https://fracpete.github.io/rsync4j/commandline
Displays the usage information and all available command-line options for the SshKeyGen tool. This is useful for understanding the full range of functionalities.
```bash
usage: com.github.fracpete.rsync4j.SshKeyGen
[-h] [--output-commandline] [-A] [-a ROUNDS] [-B] [-b BITS]
[-C COMMENT] [-D PKCS11] [-E FINGERPRINT] [-e] [-F FINDHOST]
[-f KEYFILE] [-G CANDIDATEPRIMES] [-g] [-H] [--host] [-i]
[-J SCREENNUMLINES] [-j SCREENSTARTLINE] [-K SCREENCHECKPOINT] [-k]
[-L] [-l] [-M MEMORY] [-m KEYFORMAT] [-N NEWPASSPHRASE]
[-n PRINCIPALS] [-O OPTION] [-o] [-P PASSPHRASE] [-p] [-Q] [-q]
[-R REMOVEKEYS] [-r PRINTFINGERPRINT] [-S STARTPOINT] [-s SIGNCAKEY]
[-T TESTCANDIDATEPRIMES] [-t KEYTYPE] [-u] [-V VALIDITYINTERVAL]
[-v] [-vv] [-vvv] [-W GENERATOR] [-y] [-z SERIALNUMBER]
[file [file ...]]
Authentication key generation, management and conversion.
See man page:
https://linux.die.net/man/1/ssh-keygen
positional arguments:
file The key file(s).
optional arguments:
-h, --help show this help message and exit
--output-commandline output the command-line generated for the wrapped
binary
-A For each of the key types (rsa1, rsa, dsa, ecdsa
and ed25519) for which host keys do not exist,
generate the host keys with the default key file
path, an empty passphrase, default bits for the
key type, and default comment.
-a ROUNDS When saving a new-format private key (i.e. an
ed25519 key or any SSH protocol 2 key when the -o
flag is set), this option specifies the number of
KDF (key derivation function) rounds used.
-B Show the bubblebabble digest of specified private
or public key file.
-b BITS Specifies the number of bits in the key to create.
-C COMMENT Provides a new comment.
-D PKCS11 Download the RSA public keys provided by the
PKCS#11 shared library pkcs11.
-E FINGERPRINT Specifies the hash algorithm used when displaying
key fingerprints.
-e This option will read a private or public OpenSSH
key file and print to stdout the key in one of
the formats specified by the -m option.
-F FINDHOST Search for the specified hostname in a
known_hosts file, listing any occurrences found.
-f KEYFILE Specifies the filename of the key file.
-G CANDIDATEPRIMES Generate candidate primes for DH-GEX..
-g Use generic DNS format when printing fingerprint
resource records using the -r command.
-H Hash a known_hosts file.
--host When signing a key, create a host certificate
instead of a user certificate.
-i This option will read an unencrypted private (or
public) key file in the format specified by the -
m option and print an OpenSSH compatible private
(or public) key to stdout.
-J SCREENNUMLINES Exit after screening the specified number of
lines while performing DH candidate screening
using the -T option.
-j SCREENSTARTLINE Start screening at the specified line number
while performing DH candidate screening using the
-T option.
-K SCREENCHECKPOINT Write the last line processed to the file checkpt
while performing DH candidate screening using the
-T option.
-k Generate a KRL file.
-L Prints the contents of one or more certificates.
-l Show fingerprint of specified public key file.
-M MEMORY Specify the amount of memory to use (in
megabytes) when generating candidate moduli for
DH-GEX.
-m KEYFORMAT Specify a key format for the -i (import) or -e
(export) conversion options.
-N NEWPASSPHRASE Provides the new passphrase.
-n PRINCIPALS Specify one or more principals (user or host
names) to be included in a certificate when
signing a key.
-O OPTION Specify a certificate option when signing a key.
-o Causes ssh-keygen to save private keys using the
```
--------------------------------
### Syncing Between Windows Hosts
Source: https://fracpete.github.io/rsync4j/windows
Synchronize directories between Windows hosts using UNC paths for the remote host. The source path uses Cygwin notation, while the destination path uses a UNC format.
```text
source: /cygdrive/c/some/dir/
```
```text
destination: //otherbox/C$/other/dir
```
--------------------------------
### RSync4j Named Arguments: Help and Output Control
Source: https://fracpete.github.io/rsync4j/commandline
Options for displaying help messages and controlling the output verbosity and format of the rsync process.
```bash
named arguments:
-h, --help show this help message and exit
--output-commandline output the command-line generated for the wrapped
binary
-v, --verbose increase verbosity
--info INFO fine-grained informational verbosity
--debug DEBUG fine-grained debug verbosity
--msgs2stderr special output handling for debugging
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD
```
--------------------------------
### RSync4j Named Arguments: Directory and Symlink Handling
Source: https://fracpete.github.io/rsync4j/commandline
Options for controlling how directories and symbolic links are transferred.
```bash
-d, --dirs transfer directories without recursing
-l, --links copy symlinks as symlinks
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the source tree
--munge-links munge symlinks to make them safer (but unusable)
-k, --copy-dirlinks transform symlink to a dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
```
--------------------------------
### Add rsync4j for Windows64 Support
Source: https://fracpete.github.io/rsync4j/maven
Include this dependency in your pom.xml for native Windows64 support. Ensure the version matches your project's requirements.
```xml
com.github.fracpete
rsync4j-windows64
3.3.0-7
```
--------------------------------
### RSync4j Named Arguments: Backup and Update Options
Source: https://fracpete.github.io/rsync4j/commandline
Options for managing backups of transferred files and controlling updates based on file modification times.
```bash
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir BACKUPDIR
make backups into hierarchy based in DIR
--suffix SUFFIX set backup suffix (default ~ w/o --backup-dir)
-u, --update skip files that are newer on the receiver
```
--------------------------------
### Rsync4j Ssh Tool Usage
Source: https://fracpete.github.io/rsync4j/commandline
This is the main usage help screen for the Rsync4j Ssh tool. It lists all available command-line options and their descriptions.
```bash
usage: com.github.fracpete.rsync4j.Ssh
[-h] [--output-commandline] [--maxtime MAXTIME] [-1] [-2] [-4]
[-6] [-A] [-a] [-b BINDADDRESS] [-C] [-c CIPHERSPEC]
[-D DYNAMICBINDADDRESS] [-E LOGFILE] [-e ESCAPECHAR] [-F CONFIGFILE]
[-f] [-G] [-g] [-I PKCS11] [-K] [-k] [-L LOCAL] [-l LOGINNAME] [-M]
[-m MACSPEC] [-N] [-n] [-O CONTROLCOMMAND] [-o OPTION] [-p PORT]
[-q] [-R REMOTE] [-s] [-T] [-t] [-v] [-vv] [-vvv] [-W FORWARDTO]
[-w FORWARDTUNNEL] [-X] [-x] [-Y] [-y] hostname [command]
OpenSSH SSH client (remote login program). No interactive sessions
possible.
See man page:
https://linux.die.net/man/1/ssh
positional arguments:
hostname The hostname to connect to.
The hostname to connect to.
command The remote command to execute.
optional arguments:
-h, --help show this help message and exit
--output-commandline output the command-line generated for the wrapped
binary
--maxtime MAXTIME set the maximum time for the process to run in
seconds before getting killed
-1 Forces ssh to try protocol version 1 only.
-2 Forces ssh to try protocol version 2 only.
-4 Forces ssh to use IPv4 addresses only.
-6 Forces ssh to use IPv6 addresses only.
-A Enables forwarding of the authentication agent
connection.
-a Disables forwarding of the authentication agent
connection.
-b BINDADDRESS Use bind_address on the local machine as the
source address of the connection.
-C Requests compression of all data.
-c CIPHERSPEC Selects the cipher specification for encrypting
the session.
-D DYNAMICBINDADDRESS Specifies a local “dynamic” application-level
port forwarding ([bind_address:]port).
-E LOGFILE Append debug logs to log_file instead of standard
error.
-e ESCAPECHAR Sets the escape character for sessions with a pty
(default: ‘~’).
-F CONFIGFILE Specifies an alternative per-user configuration
file.
-f Requests ssh to go to background just before
command execution.
-G Causes ssh to print its configuration after
evaluating Host and Match blocks and exit.
-g Allows remote hosts to connect to local forwarded
ports
-I PKCS11 Specify the PKCS#11 shared library ssh should use
to communicate with a PKCS#11 token providing the
user's private RSA key.
-K Enables GSSAPI-based authentication and
forwarding (delegation) of GSSAPI credentials to
the server.
-k Disables forwarding (delegation) of GSSAPI
credentials to the server.
-L LOCAL Specifies that connections to the given TCP port
or Unix socket on the local (client) host are to
be forwarded to the given host and port, or Unix
socket, on the remote side.
-l LOGINNAME Specifies the user to log in as on the remote
machine.
-M Places the ssh client into “master” mode for
connection sharing.
-m MACSPEC A comma-separated list of MAC (message
authentication code) algorithms, specified in
order of preference.
-N Do not execute a remote command. This is useful
for just forwarding ports.
-n Redirects stdin from /dev/null (actually,
prevents reading from stdin).
-O CONTROLCOMMAND Control an active connection multiplexing master
process.
-o OPTION Can be used to give options in the format used in
the configuration file.
-p PORT Port to connect to on the remote host.
-q Quiet mode. Causes most warning and diagnostic
messages to be suppressed.
-R REMOTE Specifies that connections to the given TCP port
```
--------------------------------
### Rsync with Multiple Sources (List)
Source: https://fracpete.github.io/rsync4j/java
Configures an rsync command to synchronize multiple source directories specified as a `java.util.List`. This provides flexibility in how source paths are managed.
```java
List s = new ArrayList<>();
s.add("/first/place");
s.add("/second/place");
RSync rsync = new RSync()
.sources(s)
.destination("/other/place/")
.recursive(true)
.verbose(true);
```
--------------------------------
### Using SSH with rsync4j
Source: https://fracpete.github.io/rsync4j/windows
To use SSH instead of the plain protocol, supply 'ssh' as the remote shell. This can be done in Java code via rsh() or on the command line using --rsh=ssh.
```java
rsh("ssh")
```
--------------------------------
### Execute Rsync with Custom Output Processing
Source: https://fracpete.github.io/rsync4j/java
Executes an rsync command and processes its stdout and stderr line by line using a custom `StreamingProcessOwner` implementation. This allows for granular control over how output is handled during execution.
```java
import com.github.fracpete.rsync4j.RSync;
import com.github.fracpete.processoutput4j.core.StreamingProcessOutputType;
import com.github.fracpete.processoutput4j.core.StreamingProcessOwner;
import com.github.fracpete.processoutput4j.output.StreamingProcessOutput;
public static class Output implements StreamingProcessOwner {
public StreamingProcessOutputType getOutputType() {
return StreamingProcessOutputType.BOTH;
}
public void processOutput(String line, boolean stdout) {
System.out.println((stdout ? "[OUT] " : "[ERR] ") + line);
}
}
...
RSync rsync = new RSync()
.source("/one/place/")
.destination("/other/place/")
.recursive(true)
.verbose(true);
StreamingProcessOutput output = new StreamingProcessOutput(new Output());
output.monitor(rsync.builder());
```
--------------------------------
### Rsync with Multiple Sources (Array)
Source: https://fracpete.github.io/rsync4j/java
Configures an rsync command to synchronize multiple source directories specified as a String array. Ensure all paths are correctly formatted for the operating system.
```java
String[] s = new String[]{
"/first/place/",
"/second/place/",
};
RSync rsync = new RSync()
.sources(s)
.destination("/other/place/")
.recursive(true)
.verbose(true);
```
--------------------------------
### Execute Rsync and Monitor Console Output
Source: https://fracpete.github.io/rsync4j/java
Configures and executes an rsync command, streaming stdout and stderr directly to the console as they occur. This is useful for real-time feedback during long-running rsync operations.
```java
import com.github.fracpete.rsync4j.RSync;
import com.github.fracpete.processoutput4j.output.ConsoleOutputProcessOutput;
...
RSync rsync = new RSync()
.source("/one/place/")
.destination("/other/place/")
.archive(true)
.delete(true);
ConsoleOutputProcessOutput output = new ConsoleOutputProcessOutput();
output.monitor(rsync.builder());
```
--------------------------------
### Execute Rsync and Collect Output
Source: https://fracpete.github.io/rsync4j/java
Configures and executes an rsync command, collecting all stdout and stderr after the process completes. Use this when you need the full output after the rsync operation finishes.
```java
import com.github.fracpete.rsync4j.RSync;
import com.github.fracpete.processoutput4j.output.CollectingProcessOutput;
...
RSync rsync = new RSync()
.source("/one/place/")
.destination("/other/place/")
.recursive(true);
// or if you prefer using commandline options:
// rsync.setOptions(new String[]{" -r", "/one/place/", "/other/place/"});
CollectingProcessOutput output = rsync.execute();
System.out.println(output.getStdOut());
System.out.println("Exit code: " + output.getExitCode());
if (output.getExitCode() > 0)
System.err.println(output.getStdErr());
```
--------------------------------
### Execute Remote Command via SSH
Source: https://fracpete.github.io/rsync4j/java
Use the Ssh class to execute commands on a remote host. Configure verbose output and command line logging.
```java
import com.github.fracpete.rsync4j.Ssh;
import com.github.fracpete.processoutput4j.output.ConsoleOutputProcessOutput;
...
Ssh ssh = new Ssh()
.outputCommandline(true)
.verbose(1)
.hostname("localhost")
.command("ls /tmp");
ConsoleOutputProcessOutput output = new ConsoleOutputProcessOutput();
output.monitor(ssh.builder());
```
--------------------------------
### Generate SSH Key with SshKeyGen
Source: https://fracpete.github.io/rsync4j/java
Generate an SSH key file using SshKeyGen. Specify key type, file path, and comment. Outputs the key's bubble babble representation.
```java
import com.github.fracpete.rsync4j.SshKeyGen;
import com.github.fracpete.processoutput4j.output.ConsoleOutputProcessOutput;
...
SshKeyGen keygen = new SshKeyGen()
.outputCommandline(true)
.verbose(1)
.keyType("dsa")
.newPassPhrase("")
.comment("test key")
.keyFile("~/testkey");
ConsoleOutputProcessOutput output = new ConsoleOutputProcessOutput();
output.monitor(keygen.builder());
```
--------------------------------
### Specify SSH Identity File with rsync
Source: https://fracpete.github.io/rsync4j/faq
Use the `--rsh` option with `ssh -i` to specify a particular private key file for authentication. This is useful when you need to use a key pair other than the default.
```bash
rsync --rsh="ssh -i /some/where/id_rsa" ...
```
--------------------------------
### RSync4j Positional Arguments
Source: https://fracpete.github.io/rsync4j/commandline
Defines the source and destination paths for the rsync operation. The last argument is the target destination, and all preceding arguments are sources.
```bash
positional arguments:
source(s)/destination Multiple local/remote paths (path or [user@]host:
path), with the last one being the target and the
others the source(s).
```
--------------------------------
### RSync4j Named Arguments: In-Place and Append Transfer
Source: https://fracpete.github.io/rsync4j/commandline
Options for updating files directly in place or appending data to existing files.
```bash
--inplace update destination files in-place
--append append data onto shorter files
--append-verify like --append, but with old data in file checksum
```
--------------------------------
### RSync4j Named Arguments: Metadata Preservation
Source: https://fracpete.github.io/rsync4j/commandline
Options for preserving file metadata such as hard links, permissions, and ownership during transfer.
```bash
-H, --hard-links preserve hard links
-p, --perms preserve permissions
```
--------------------------------
### RSync4j Named Arguments: File Transfer Control
Source: https://fracpete.github.io/rsync4j/commandline
Options that dictate how files are compared and transferred, including checksum usage, archive mode, and recursion.
```bash
-c, --checksum skip based on checksum, not mod-time & size
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
-r, --recursive recurse into directories
-R, --relative use relative path names
--no-implied-dirs use relative path names
```
--------------------------------
### SSH Connection with Password Authentication
Source: https://fracpete.github.io/rsync4j/java
Connect to a remote host using password authentication via SshPass. This is an alternative when SSH keys are not feasible. Configure SSH options like host key checking.
```java
import com.github.fracpete.rsync4j.Ssh;
import com.github.fracpete.rsync4j.SshPass;
import com.github.fracpete.processoutput4j.output.ConsoleOutputProcessOutput;
...
SshPass sshpass = new SshPass()
.password("mysecretpassword");
Ssh ssh = new Ssh()
.sshPass(sshpass)
.option("StrictHostKeyChecking=no")
.hostname("username@remote.host.com")
.command("ls /tmp");
ConsoleOutputProcessOutput output = new ConsoleOutputProcessOutput();
output.monitor(ssh.builder());
```
--------------------------------
### Suppress SSH Host Key Checking
Source: https://fracpete.github.io/rsync4j/faq
To avoid the prompt for accepting a remote host's fingerprint, include `StrictHostKeyChecking=no` in the SSH options passed via the `-o` flag. This is often used in automated scripts.
```bash
ssh -o StrictHostKeyChecking=no ...
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.