jord-jd / php-file-sync
Synchronise files between multiple local or remote file systems
Fund package maintenance!
Requires
- php: >=7.1
- jord-jd/php-cli-progress-bar: ^4.0
- league/flysystem: ^1.0
- nesbot/carbon: ^1.0||^2.27
Requires (Dev)
- phpunit/phpunit: ^7.5||^9.6
Replaces
- divineomega/php-file-sync: v3.0.1
This package is auto-updated.
Last update: 2026-07-18 01:15:48 UTC
README
Synchronise files between multiple local or remote filesystems through Flysystem 1.x.
Installation
composer require jord-jd/php-file-sync
Create each filesystem with the appropriate Flysystem adapter. The examples below use local adapters, but the synchronisation strategies work with any Flysystem 1.x Filesystem instance.
use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; $source = new Filesystem(new Local('/path/to/source')); $destination = new Filesystem(new Local('/path/to/destination'));
One-way synchronisation
One-way synchronisation copies files that are missing from the destination, plus source files whose timestamps are newer. It does not delete destination-only files.
use JordJD\FileSync\FileSync; (new FileSync()) ->oneWay() ->from($source) ->to($destination) ->begin();
Multi-directional synchronisation
Multi-directional synchronisation makes the newest version of each file available on every configured filesystem. Files that exist on only one filesystem are copied to the others.
(new FileSync()) ->multiDirectional() ->with($filesystemA) ->with($filesystemB) ->with($filesystemC) ->begin();
Add ->withProgressBar() before ->begin() on either strategy to show command-line progress.
Important behavior
- Paths are compared exactly as returned by Flysystem.
- Modification timestamps decide which version is newer.
- Existing files may be overwritten by newer copies.
- Deletions are not propagated.
- Check the boolean result or exceptions produced by your Flysystem adapter when storage failures need application-specific handling.