From: Vincent Vanwaelscappel Date: Fri, 27 Jan 2023 14:43:13 +0000 (+0100) Subject: wip #5700 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ee5c93333942a0c69bcef25309732361b1522072;p=cubist_util.git wip #5700 @0.25 --- diff --git a/src/CommandLine/LFTP.php b/src/CommandLine/LFTP.php index a1be0ee..d241ae0 100644 --- a/src/CommandLine/LFTP.php +++ b/src/CommandLine/LFTP.php @@ -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)); } /**