2017 © Pedro Peláez
 

library sync-sftp

Sync local files with ftp server

image

glicer/sync-sftp

Sync local files with ftp server

  • Saturday, August 27, 2016
  • by emmanuelroecker
  • Repository
  • 2 Watchers
  • 9 Stars
  • 139 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 4 % Grown

The README.md

php-sync-sftp

Scrutinizer Code Quality Build Status Coverage Status SensioLabsInsight Dependency Status, (*1)

Synchronize local files with sftp (ssh ftp) server., (*2)

Compare dates between local and remote files, not using crc.(cyclic redundancy check), and update files only on remote sftp server., (*3)

Installation

This library can be found on Packagist., (*4)

The recommended way to install is through composer., (*5)

Edit your composer.json and add:, (*6)

{
    "require": {
       "glicer/sync-sftp": "dev-master"
    },
    "prefer-stable": true,
    "minimum-stability": "dev"
}

And install dependencies:, (*7)

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), (*8)

With Docker :, (*9)

(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 :, (*10)

vendor\bin\phpunit

Change ftp server config in file : phpunit.xml.dist, (*11)

License MIT

Contact

Authors : Emmanuel ROECKER & Rym BOUCHAGOUR, (*12)

Web Development Blog - http://dev.glicer.com, (*13)

The Versions

27/08 2016