]> _ Git - cubist_util.git/commitdiff
wip #5700 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 11:58:56 +0000 (12:58 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 11:58:56 +0000 (12:58 +0100)
src/CommandLine/CloneProgram.php [new file with mode: 0644]
src/CommandLine/CloneUserpassProgram.php [new file with mode: 0644]
src/CommandLine/LFTP.php [new file with mode: 0644]
src/CommandLine/Rclone.php
src/CommandLine/Rsync.php

diff --git a/src/CommandLine/CloneProgram.php b/src/CommandLine/CloneProgram.php
new file mode 100644 (file)
index 0000000..60cb1ab
--- /dev/null
@@ -0,0 +1,107 @@
+<?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
diff --git a/src/CommandLine/CloneUserpassProgram.php b/src/CommandLine/CloneUserpassProgram.php
new file mode 100644 (file)
index 0000000..167b10b
--- /dev/null
@@ -0,0 +1,124 @@
+<?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
diff --git a/src/CommandLine/LFTP.php b/src/CommandLine/LFTP.php
new file mode 100644 (file)
index 0000000..a1be0ee
--- /dev/null
@@ -0,0 +1,60 @@
+<?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
index 30c60694688e4f19025e585d6d4e97ffa1c86882..94634b59aa4872970334c879d4ce4ed12d128200 100644 (file)
@@ -4,118 +4,27 @@ namespace Cubist\Util\CommandLine;
 
 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()) {
index c7e190f76103969e78e4a6ff1ae3675d10957768..c73a94c2d52180840753f747c9969b61f2d4ab6f 100644 (file)
@@ -5,21 +5,16 @@ namespace Cubist\Util\CommandLine;
 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()
     {
@@ -54,59 +49,11 @@ class Rsync extends CommandLine
         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)
     {
@@ -124,7 +71,6 @@ class Rsync extends CommandLine
         $src = $this->getSrc();
         $mirror = $this->getMirror();
 
-
         $destDistant = stristr($dest, '@');
         if ($destDistant) {
             list($distServer, $distDir) = explode(':', $dest, 2);
@@ -132,7 +78,6 @@ class Rsync extends CommandLine
             $dest = $distServer . ':\'' . $distDir . '\'';
         }
 
-
         if (!file_exists($dest)) {
             if (!$destDistant) {
                 Files::mkdir($dest);
@@ -170,27 +115,11 @@ class Rsync extends CommandLine
 
     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;
-    }
-
 }