Example #1
0
 /**
  * Gets command generated for this current
  * rsync configuration. You can use it to test
  * or execute it later without using the sync method
  *
  * @param $origin
  * @param $target
  *
  * @return Command
  */
 public function getCommand($origin, $target)
 {
     $command = new Command($this->executable);
     if ($this->skipNewerFiles) {
         $command->addOption("u");
     }
     if ($this->followSymLinks) {
         $command->addOption("L");
     }
     if ($this->dryRun) {
         $command->addOption("n");
     }
     if ($this->verbose) {
         $command->addOption("v");
     }
     if ($this->times) {
         $command->addArgument('times');
     }
     if ($this->deleteFromTarget) {
         $command->addArgument('delete');
     }
     if ($this->deleteExcluded) {
         $command->addArgument('delete-excluded');
     }
     if (!empty($this->exclude)) {
         foreach ($this->exclude as $excluded) {
             $command->addArgument('exclude', $excluded);
         }
     }
     if ($this->archive) {
         $command->addOption("a");
     }
     if (!$this->archive && $this->recursive) {
         $command->addOption("r");
     }
     if (!is_null($this->ssh)) {
         $ssh = $this->ssh->getConnectionOptions();
         $command->addArgument("rsh", $ssh);
     }
     $command->addParameter($origin);
     if (is_null($this->ssh)) {
         $command->addParameter($target);
     } else {
         $command->addParameter($this->ssh->getHostConnection() . ":" . $target);
     }
     return $command;
 }
Example #2
0
 /**
  * Gets command generated for this current
  * rsync configuration. You can use it to test
  * or execute it later without using the sync method
  *
  * @param $origin
  * @param $target
  *
  * @return Command
  */
 public function getCommand($origin, $target)
 {
     $command = new Command($this->executable);
     if ($this->skipNewerFiles) {
         $command->addOption("u");
     }
     if ($this->followSymLinks) {
         $command->addOption("L");
     }
     if ($this->dryRun) {
         $command->addOption("n");
     }
     if ($this->verbose) {
         $command->addOption("v");
     }
     if ($this->compression) {
         $command->addOption("z");
     }
     // add any optional options we've specified
     $extra_options = $this->getOptionalParameters();
     if (!empty($extra_options)) {
         // if the extra options were given as a flat string, then convert it to an array
         if (is_string($extra_options)) {
             $extra_options = str_split($extra_options);
         }
         // add each extra option we've defined.
         if (is_array($extra_options)) {
             foreach ($extra_options as $option) {
                 $command->addOption($option);
             }
         }
     }
     if ($this->times) {
         $command->addArgument('times');
     }
     if ($this->deleteFromTarget) {
         $command->addArgument('delete');
     }
     if ($this->removeSource) {
         $command->addArgument('remove-source-files');
     }
     if ($this->deleteExcluded) {
         $command->addArgument('delete-excluded');
     }
     if ($this->info) {
         $command->addArgument('info', $this->info);
     }
     if ($this->compareDest) {
         $command->addArgument('compare-dest', $this->compareDest);
     }
     if (!empty($this->exclude)) {
         foreach ($this->exclude as $excluded) {
             $command->addArgument('exclude', $excluded);
         }
     }
     if (!empty($this->excludeFrom)) {
         $command->addArgument('exclude-from', $this->excludeFrom);
     }
     if ($this->archive) {
         $command->addOption("a");
     }
     if (!$this->archive && $this->recursive) {
         $command->addOption("r");
     }
     if (!is_null($this->ssh)) {
         $ssh = $this->ssh->getConnectionOptions();
         $command->addArgument("rsh", $ssh);
     }
     if (is_null($this->ssh)) {
         $command->addParameter($origin);
         $command->addParameter($target);
     } elseif ($this->remoteOrigin) {
         $command->addParameter($this->ssh->getHostConnection() . ":" . $origin);
         $command->addParameter($target);
     } else {
         $command->addParameter($origin);
         $command->addParameter($this->ssh->getHostConnection() . ":" . $target);
     }
     return $command;
 }
Example #3
0
 /**
  * Gets commands for this SSH connection
  *
  * @param bool $hostConnection
  *
  * @return string
  *
  * @throws \InvalidArgumentException If you don't specify a SSH username or host
  */
 public function getCommand($hostConnection = true)
 {
     if (is_null($this->username)) {
         throw new \InvalidArgumentException("You must specify a SSH username");
     }
     if (is_null($this->host)) {
         throw new \InvalidArgumentException("You must specify a SSH host to connect");
     }
     $command = new Command($this->executable);
     if ($this->port != 22) {
         $command->addArgument("p", $this->port);
     }
     if (!is_null($this->publicKey)) {
         $command->addArgument("i", $this->publicKey);
     }
     if ($hostConnection) {
         $command->addParameter($this->getHostConnection());
     }
     return $command;
 }