namespace Cubist\Util\CommandLine;
+use Cubist\Net\Transfer\IServer;
use Cubist\Util\CommandLine;
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));
}
/**