Skip to content

kenichiii/php-sync-sftp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-sync-sftp

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

<?php
// Must point to composer's autoload file.
require 'vendor/autoload.php';

use GlSyncFtp\GlSyncFtp;

//init connection informations
$ftp = new GlSyncFtp("192.168.0.1", "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)

Change ftp server config in file : phpunit.xml.dist

Launch from command line :

vendor\bin\phpunit

Contact

Authors : Emmanuel ROECKER & Rym BOUCHAGOUR

Web Development Blog - http://dev.glicer.com

About

Synchronize local files with sftp (ssh ftp) server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%