glicer / sync-sftp
Sync local files with ftp server
dev-master
2016-08-27 11:21 UTC
Requires
- php: >=5.5
- phpseclib/phpseclib: ~2.0
- symfony/finder: ~2.3 || ~3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
- satooshi/php-coveralls: ~1.0
This package is not auto-updated.
Last update: 2024-11-09 18:59:19 UTC
README
Synchronize local files with sftp (ssh ftp) server.
Compare dates between local and remote files, not using crc.(cyclic redundancy check), and update files only on remote sftp server.
Installation
This library can be found on Packagist.
The recommended way to install is through composer.
Edit your composer.json
and add:
{ "require": { "glicer/sync-sftp": "dev-master" }, "prefer-stable": true, "minimum-stability": "dev" }
And install dependencies:
php composer.phar install
Example
// Must point to composer's autoload file. require 'vendor/autoload.php'; use GlSyncFtp\GlSyncFtp; //init connection informations $ftp = new GlSyncFtp("192.168.0.1", 22, "username", "password"); //launch synchronisation between local directory and remote files $ftp->syncDirectory( "/home/user/localDirectory", //local source directory "/host/web/remoteDirectory", //remote destination directory function ($op, $path) { switch ($op) { case GlSyncFtp::CREATE_DIR: echo "Create Directory : "; break; case GlSyncFtp::DELETE_DIR: echo "Delete Directory : "; break; case GlSyncFtp::DELETE_FILE: echo "Delete File : "; break; case GlSyncFtp::UPDATE_FILE: echo "Update File : "; break; case GlSyncFtp::NEW_FILE: echo "New File : "; break; default: } echo $path . "\n"; } ); //launch synchronisation between list of local directories and remote directories $fps->syncDirectories( [ "/home/user/localDirectory1" => "/host/web/remoteDirectory1", "/home/user/localDirectory2" => "/host/web/remoteDirectory2" ], function ($src, $dst) { echo "Sync directory : $src with $dst"; }, function ($op, $path) { switch ($op) { case GlSyncFtp::CREATE_DIR: echo "Create Directory : "; break; case GlSyncFtp::DELETE_DIR: echo "Delete Directory : "; break; case GlSyncFtp::DELETE_FILE: echo "Delete File : "; break; case GlSyncFtp::UPDATE_FILE: echo "Update File : "; break; case GlSyncFtp::NEW_FILE: echo "New File : "; break; default: } echo $path . "\n"; } );
Running Tests
Local ssh ftp server must be installed (On Windows, you can use cygwin openssh)
With Docker :
(cd docker ; sudo tar xpvzf docker.tar.gz) docker pull rhasselbaum/scrappy-sftp docker run -d --name sftp -p 2022:22 -v /$(pwd)/docker/sftp-root:/sftp-root -v /$(pwd)/docker/credentials:/creds rhasselbaum/scrappy-sftp
Launch from command line :
vendor\bin\phpunit
Change ftp server config in file : phpunit.xml.dist
License MIT
Contact
Authors : Emmanuel ROECKER & Rym BOUCHAGOUR