PHP code example of sudnonk / php-rsync
1. Go to this page and download the library: Download sudnonk/php-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/ */
sudnonk / php-rsync example snippets
$rsync->run();//の前に!!!!!!!!!
echo $rsync->build(); //で確認すること!!!!!!
$rsync = new Rsync();
$rsync = new Rsync(true);
$rsync->set_from(string ディレクトリ名,bool 中身だけか, string ユーザ名, string ホスト);
//例
$rsync->set_from("/remote/test",true,"root","localhost");
$rsync->set_from("/local/test2",false);
$rsync->set_to(string ディレクトリ名, string ユーザ名, string ホスト);
//例
$rsync->set_to("/remote/test","root","localhost");
$rsync->set_to("/local/test2");
//パラメータつきのオプションをセットするとき
$rsync->options()->set(string オプション名, string パラメータ);
//パラメータ無しのをまとめてセットするとき
$rsync->options()->sets(string オプション名, string オプション名, ...);
//例
$rsync->options()->set("ignore-times");
$rsync->options()->set("timeout", "5");
$rsync->options()->sets("a", "v", "z", "stats");
//コピー元にないファイルをコピー先から削除する
$rsync->options()->setDelete();
//どんな動作をするかを実際には行わずに確認する
$rsync->options()->setDryRun();
//SSHのオプションをセット
$rsync->ssh_options()->set(string オプション名, string パラメータ);
//例
$rsync->ssh_options()->set("C");
$rsync->ssh_options()->set("F", "/path/to/config");
//接続先ポートを10022番にする
$rsync->ssh_options()->setPort(10022);
//公開鍵ファイルを指定する
$rsync->ssh_options()->setCert("/path/to/cert");
//実行する
$rsync->run();
//コマンドだけを組み立てる
$command = $rsync->build();
var_dump($command);
//rsync -a -u -z --stat -e 'ssh -i /path/to/cert' /local/test [email protected] :/remote/test