]> _ Git - cubist_util.git/commitdiff
wip #5700 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 14:43:13 +0000 (15:43 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 14:43:13 +0000 (15:43 +0100)
src/CommandLine/LFTP.php

index a1be0ee58bfabc99e4ccf9324c50477b667084d4..d241ae0c7bf6a672e6d9a34dec9eaa0b5449b320 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Cubist\Util\CommandLine;
 
+use Cubist\Net\Transfer\IServer;
 use Cubist\Util\CommandLine;
 
 class LFTP extends CloneUserpassProgram
@@ -11,34 +12,61 @@ class LFTP extends CloneUserpassProgram
     /**
      * @var bool
      */
-    protected $_passiveMode=false;
-
+    protected $_passiveMode = false;
 
 
+    public function setServer(IServer $server)
+    {
+        parent::setServer($server);
+        $settings = $server->getSettings();
+        if (isset($settings['ftp_mode'])) {
+            $this->setPassiveMode($settings['ftp_mode'] == '0');
+        }
+    }
 
 
     protected function _preExecute()
     {
         parent::_preExecute();
 
-        $commandes = [
-            'set ftp:ssl-allow false',
+        $commands = [
             'set net:reconnect-interval-base 5',
             'set net:max-retries 2',
-            'set ftp:passive-mode ' .($this->isPassiveMode()?'1':'0'),
+            'set ftp:passive-mode ' . ($this->isPassiveMode() ? '1' : '0')
+        ];
+        switch ($this->getProtocol()) {
+            case 'ftp':
+                $commands += [
+                    'set ftp:ssl-allow false',
+                    'connect ftp://' . $this->getHost()
+                ];
+                break;
+            case 'ftps':
+                $commands += ['connect ftps://' . $this->getHost()];
+                break;
+            case 'ftpes':
+                $commands += [
+                    'set ftp:ssl-force true',
+                    'connect ftp://' . $this->getHost()
+                ];
+        }
+
+        $commands += [
             'mkdir -p ' . $this->getDest(),
             'cd ' . $this->getDest(),
-            'lcd ' .$this->getSrc(),
-            'mirror -Rve --parallel=5'
-         ];
-
-        //$lftp->setManualArg( . '> mirror -Rv ' . $package);
-
-
+            'lcd ' . $this->getSrc(),
+        ];
+        $mirrorCmd = 'mirror --reverse --verbose --parallel=5';
+        if ($this->getMirror()) {
+            $mirrorCmd .= ' --delete';
+        }
+        if ($this->isDryRun()) {
+            $mirrorCmd .= ' --dry-run';
+        }
+        $commands[] = $mirrorCmd;
         $this->setArg('u', $this->getUsername() . ',' . $this->getPassword());
         $this->setArg('p', $this->getPort());
-        $this->setArg('e', implode(';', $commandes));
-        $this->setArg(null, $u['host']);
+        $this->setArg('e', implode(';', $commands));
     }
 
     /**