PHP code example of xobotyi / rsync

1. Go to this page and download the library: Download xobotyi/rsync library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xobotyi / rsync example snippets


use xobotyi\rsync\Rsync;

$rsync = new Rsync();
$rsync->sync('/path/to/source', '/path/to/destination');

use xobotyi\rsync\Rsync;
use xobotyi\rsync\SSH;

$rsync = new Rsync([
                       Rsync::CONF_CWD        => __DIR__,
                       Rsync::CONF_EXECUTABLE => '/even/alternative/executable/rsync.exe',
                       Rsync::CONF_SSH        => [
                           SSH::CONF_EXECUTABLE => '/even/alternative/executable/ssh.exe',
                           SSH::CONF_OPTIONS    => [
                               SSH::OPT_OPTION              => ['BatchMode=yes', 'StrictHostKeyChecking=no'],
                               SSH::OPT_IDENTIFICATION_FILE => './path/to/ident',
                               SSH::OPT_PORT                => 2222,
                           ],
                       ],
                   ]);
$rsync->sync('./relative/path/to/source', '[email protected]:/abs/path/to/destination');
echo './relative/path/to/source ' . ($rsync->getExitCode() === 0 ? 'successfully synchronized with remote.' : 'not synchronised due to errors.') . "\n";

$rsync->setExecutable('ssh')
      ->setOption(SSH::OPT_OPTION, false)// 'false' value turns off the options
      ->setOptions([
                       SSH::OPT_IDENTIFICATION_FILE => './new/path/to/ident',
                       SSH::OPT_PORT                => 22,
                   ]);
$rsync->sync('/new/path/to/source', '[email protected]:/abs/path/to/destination');
echo '/new/path/to/source ' . ($rsync->getExitCode() === 0 ? 'successfully synchronized with remote.' : 'not synchronised due to errors.') . "\n";