Example #1
0
<?php

require 'lib/FTPSync.php';
set_time_limit(0);
$sync = new FtpSync('127.0.0.1', 'Amin', '123');
$sync->enableLog()->reportOnly(true)->ignore('.DS_Store')->ignore('.settings')->ignore('.buildpath')->ignore('.project')->useStrategy(FtpSync::SYNC_BY_SIZE)->remote('/Library/WebServer/Documents/SN', '/Users/Amin/Downloads/Test');
Example #2
0
 /**
  * Gets Command Line Interface.(only in shell environment)
  *
  * @static
  * @access public
  * @return FTPSync instance of this class 
  */
 public function getCli()
 {
     //STDIN constant is not defined in non-CLI environment
     if (!defined("STDIN")) {
         echo "This method should be run in CLI";
         return false;
     }
     echo "Host Name: ";
     $host = $this->_read();
     echo "FTP Username: "******"FTP Password: "******"FTP Port[21]: ";
     $port = $this->_read();
     $port = !$port ? 21 : (int) $port;
     echo "Connecting to {$user}@{$host}...\n";
     // create an instance of FTPSync with given parameters
     try {
         $ftp = new FtpSync($host, $user, $pass, $port);
     } catch (Exception $e) {
         die($e->getMessage());
     }
     echo "Connected.\n";
     echo "Set passive? yes[no] ";
     if ($this->_isYes()) {
         $ftp->setPassive(true);
     }
     echo "Would you like to configure the options? yes[no]: ";
     if ($this->_isYes()) {
         echo "Please select the mode:\n" . "[1] - Auto \n" . "2 - ASCII \n" . "3 - Binary \n";
         $answer = $this->_read();
         if ($answer == 2) {
             $ftp->setMode(FTP_ASCII);
         } elseif ($answer == 3) {
             $ftp->setMode(FTP_BINARY);
         }
         echo "Would you like newer files in remote host to be " . "downloaded into local host or vice versa? yes[no] " . "(Note: your local file might be replaced " . "with newer one in remote host or vice versa)\n";
         if ($this->_isYes()) {
             $ftp->reportOnly(false);
         } else {
             $ftp->reportOnly(true);
         }
         echo "Would you like logs to be written in external file? " . "yes[no] \n";
         if ($this->_isYes()) {
             $ftp->enableLog();
             enter_logpath:
             echo "Please enter your log file path:" . "[" . $ftp->getLogger()->getLogFile() . "] \n";
             $logPath = trim(fgets(STDIN));
             if ($logPath) {
                 if (!is_writable($logPath)) {
                     echo "'" . $logPath . "' is not writable, " . "Please enter a valid path:";
                     goto enter_logpath;
                 } else {
                     $ftp->getLogger()->setLogFile($logPath);
                 }
             }
         }
         echo "if you have files or directories to exclude, " . "please insert(serperate their paths with comma):\n";
         //get comma seperated list of directories that must be excluded
         $excludes = trim(fgets(STDIN));
         if ($excludes) {
             $aExcludes = split(",", $excludes);
             foreach ($aExcludes as $ex) {
                 $ftp->ignore(trim($ex));
             }
         }
     }
     echo "Starting...\n";
     $this->_showOptions($ftp);
 }