--- /dev/null
+<?php
+
+namespace Cubist\Util\CommandLine;
+
+use Cubist\Util\CommandLine;
+
+class CloneProgram extends CommandLine
+{
+ /**
+ * @var string
+ */
+ protected $_src;
+
+ /**
+ * @var string
+ */
+ protected $_dest;
+ /**
+ * @var bool
+ */
+ protected $_mirror = false;
+
+ /**
+ * @var bool
+ */
+ protected $_dryRun = false;
+
+ /**
+ * @var string
+ */
+ protected $_prog;
+
+ /**
+ * @var array
+ */
+ protected $_cloneArgs = [];
+
+
+ public function __construct($output = null, $error = true)
+ {
+ parent::__construct($this->_prog, $output, $error);
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getProg()
+ {
+ return $this->_prog;
+ }
+
+ /**
+ * @param bool $dryRun
+ */
+ public function setDryRun(bool $dryRun): void
+ {
+ $this->_dryRun = $dryRun;
+ }
+
+ /**
+ * @return bool
+ */
+ public function isDryRun(): bool
+ {
+ return $this->_dryRun;
+ }
+
+
+ public function getSrc()
+ {
+ return $this->_src;
+ }
+
+ public function getDest()
+ {
+ return $this->_dest;
+ }
+
+ public function getMirror()
+ {
+ return $this->_mirror;
+ }
+
+ public function setSrc($src)
+ {
+ $this->_src = $src;
+ return $this;
+ }
+
+ public function setDest($dest)
+ {
+ $this->_dest = $dest;
+ return $this;
+ }
+
+ public function setMirror($mirror)
+ {
+ $this->_mirror = $mirror;
+ return $this;
+ }
+
+ public function setCloneArg($name, $value = null)
+ {
+ $this->_cloneArgs[] = [$name, $value];
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Cubist\Util\CommandLine;
+
+use Cubist\Net\Transfer\IServer;
+
+class CloneUserpassProgram extends CloneProgram
+{
+
+ /**
+ * @var string
+ */
+ protected $_username = '';
+
+ /**
+ * @var string
+ */
+ protected $_password = '';
+
+ /**
+ * @var int
+ */
+ protected $_port = 21;
+
+ /**
+ * @var string
+ */
+ protected $_protocol = 'ftp';
+
+ /**
+ * @var string
+ */
+ protected $_host = '';
+
+
+ /**
+ * @return string
+ */
+ public function getUsername(): string
+ {
+ return $this->_username;
+ }
+
+ /**
+ * @param string $username
+ */
+ public function setUsername(string $username): void
+ {
+ $this->_username = $username;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPassword(): string
+ {
+ return $this->_password;
+ }
+
+ /**
+ * @param string $password
+ */
+ public function setPassword(string $password): void
+ {
+ $this->_password = $password;
+ }
+
+ /**
+ * @return int
+ */
+ public function getPort(): int
+ {
+ return $this->_port;
+ }
+
+ /**
+ * @param int $port
+ */
+ public function setPort(int $port): void
+ {
+ $this->_port = $port;
+ }
+
+ /**
+ * @param string $protocol
+ */
+ public function setProtocol(string $protocol): void
+ {
+ $this->_protocol = $protocol;
+ }
+
+ /**
+ * @return string
+ */
+ public function getProtocol(): string
+ {
+ return $this->_protocol;
+ }
+
+ /**
+ * @return string
+ */
+ public function getHost(): string
+ {
+ return $this->_host;
+ }
+
+ /**
+ * @param string $host
+ */
+ public function setHost(string $host): void
+ {
+ $this->_host = $host;
+ }
+
+ public function setServer(IServer $server)
+ {
+ $this->setProtocol($server->getProtocol());
+ $this->setHost($server->getHost());
+ $this->setPort($server->getPort());
+ $this->setUsername($server->getUsername());
+ $this->setPassword($server->getPassword());
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Cubist\Util\CommandLine;
+
+use Cubist\Util\CommandLine;
+
+class LFTP extends CloneUserpassProgram
+{
+ protected $_prog = '/usr/bin/lftp';
+
+ /**
+ * @var bool
+ */
+ protected $_passiveMode=false;
+
+
+
+
+
+ protected function _preExecute()
+ {
+ parent::_preExecute();
+
+ $commandes = [
+ 'set ftp:ssl-allow false',
+ 'set net:reconnect-interval-base 5',
+ 'set net:max-retries 2',
+ 'set ftp:passive-mode ' .($this->isPassiveMode()?'1':'0'),
+ 'mkdir -p ' . $this->getDest(),
+ 'cd ' . $this->getDest(),
+ 'lcd ' .$this->getSrc(),
+ 'mirror -Rve --parallel=5'
+ ];
+
+ //$lftp->setManualArg( . '> mirror -Rv ' . $package);
+
+
+ $this->setArg('u', $this->getUsername() . ',' . $this->getPassword());
+ $this->setArg('p', $this->getPort());
+ $this->setArg('e', implode(';', $commandes));
+ $this->setArg(null, $u['host']);
+ }
+
+ /**
+ * @return bool
+ */
+ public function isPassiveMode(): bool
+ {
+ return $this->_passiveMode;
+ }
+
+ /**
+ * @param bool $passiveMode
+ */
+ public function setPassiveMode(bool $passiveMode): void
+ {
+ $this->_passiveMode = $passiveMode;
+ }
+
+}
\ No newline at end of file
use Cubist\Util\CommandLine;
-class Rclone extends CommandLine
+class Rclone extends CloneUserpassProgram
{
- protected $_prog = '/usr/bin/rclone';
- /**
- * @var string
- */
- protected $_src;
- /**
- * @var string
- */
- protected $_dest;
- /**
- * @var bool
- */
- protected $_mirror = false;
-
- /**
- * @var bool
- */
- protected $_dryRun = false;
-
/**
* @var string
*/
protected $_protocol = 'local';
- protected $_rcloneArgs = [];
-
- public function __construct($output = null, $error = true)
- {
- parent::__construct($this->_prog, $output, $error);
- }
-
- public function getSrc()
- {
- return $this->_src;
- }
-
- public function getDest()
- {
- return $this->_dest;
- }
-
- public function getMirror()
- {
- return $this->_mirror;
- }
-
- public function setSrc($src)
- {
- $this->_src = $src;
- return $this;
- }
-
- public function setDest($dest)
- {
- $this->_dest = $dest;
- return $this;
- }
-
- public function setMirror($mirror)
- {
- $this->_mirror = $mirror;
- return $this;
- }
-
- public function setRcloneArg($name, $value = null)
- {
- $this->_rcloneArgs[] = [$name, $value];
- }
-
- /**
- * @param bool $dryRun
- */
- public function setDryRun(bool $dryRun): void
- {
- $this->_dryRun = $dryRun;
- }
-
- /**
- * @return string
- */
- public function getProtocol(): string
- {
- return $this->_protocol;
- }
-
- /**
- * @param string $protocol
- */
- public function setProtocol(string $protocol): void
- {
- $this->_protocol = $protocol;
- }
-
- /**
- * @return bool
- */
- public function isDryRun(): bool
- {
- return $this->_dryRun;
- }
protected function _preExecute()
{
parent::_preExecute();
$this->setArg(null, $this->getMirror() ? 'sync' : 'copy');
$this->setArg(null, $this->getSrc());
+ $this->setArg('sftp-host', $this->getHost());
+ $this->setArg('sftp-port', $this->getPort());
+ $this->setArg('sftp-user', $this->getUsername());
+ $this->setArg('sftp-pass', $this->getPassword());
if ($this->isDryRun()) {
$this->setArg('dry-run');
}
- foreach ($this->_rcloneArgs as $name => $value) {
+ foreach ($this->_cloneArgs as $name => $value) {
$this->setArg($name, $value);
}
switch ($this->getProtocol()) {
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
-class Rsync extends CommandLine
+class Rsync extends CloneProgram
{
protected $_port = 22;
- protected $_src;
- protected $_dest;
- protected $_mirror = false;
+
protected $_excludes = array();
protected $_deleteExcluded = false;
- protected $_prog = '/usr/bin/rsync';
+
protected $_sshKey = null;
- /**
- * @var bool
- */
- protected $_dryRun = false;
+
public function getSshKey()
{
return $this;
}
- public function getSrc()
- {
- return $this->_src;
- }
-
- public function getDest()
- {
- return $this->_dest;
- }
-
- public function getMirror()
- {
- return $this->_mirror;
- }
-
- public function setSrc($src)
- {
- $this->_src = $src;
- return $this;
- }
-
- public function setDest($dest)
- {
- $this->_dest = $dest;
- return $this;
- }
-
- public function setMirror($mirror)
- {
- $this->_mirror = $mirror;
- return $this;
- }
-
public function addExclude($exclude)
{
$this->_excludes[] = $exclude;
}
- /**
- * @return string
- */
- public function getProg()
- {
- return $this->_prog;
- }
-
- /**
- * @param string $prog
- */
- public function setProg($prog)
- {
- $this->_prog = $prog;
- }
public function _fixPath($path)
{
$src = $this->getSrc();
$mirror = $this->getMirror();
-
$destDistant = stristr($dest, '@');
if ($destDistant) {
list($distServer, $distDir) = explode(':', $dest, 2);
$dest = $distServer . ':\'' . $distDir . '\'';
}
-
if (!file_exists($dest)) {
if (!$destDistant) {
Files::mkdir($dest);
public function __construct($src, $dest, $mirror = false, $output = null, $error = true)
{
- parent::__construct($this->_prog, $output, $error);
+ parent::__construct($output, $error);
$this->setSrc($src);
$this->setDest($dest);
$this->setMirror($mirror);
}
- /**
- * @param bool $dryRun
- */
- public function setDryRun(bool $dryRun): void
- {
- $this->_dryRun = $dryRun;
- }
-
- /**
- * @return bool
- */
- public function isDryRun(): bool
- {
- return $this->_dryRun;
- }
-
}