From: Vincent Vanwaelscappel Date: Fri, 27 Jan 2023 07:49:39 +0000 (+0100) Subject: wip #5700 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=afc022a3a2f8934c321d8f1ab3b36a0d716254cd;p=cubist_net.git wip #5700 @1 --- diff --git a/composer.json b/composer.json index 530dc19..274046b 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,10 @@ ], "require": { "php": ">=5.4.0", - "ext-ssh2": "*" + "ext-ssh2": "*", + "cubist/util": "dev-master" + }, + "suggest": { + } } diff --git a/src/Transfer/Driver.php b/src/Transfer/Driver.php index 29f00a0..caa42e8 100644 --- a/src/Transfer/Driver.php +++ b/src/Transfer/Driver.php @@ -2,7 +2,10 @@ namespace Cubist\Net\Transfer; -class Driver { +use Cubist\Util\CommandLine; +use Cubist\Util\Text; + +abstract class Driver { /** * @var IServer @@ -27,4 +30,19 @@ class Driver { public function setServer($server) { $this->_server = $server; } + + protected static function _cleanInstallDir($path) { + $path = str_replace('/\.{2,}/', '', $path); + $path = preg_replace('/\/{2,}/', '/', $path); + $path = trim($path, '/'); + return Text::str2URL($path, '-', true); + } + + /** + * @param $source string + * @param $dest string + * @param $mirror bool + * @return CommandLine + */ + abstract public function copy($source, $dest, $mirror = false); } \ No newline at end of file diff --git a/src/Transfer/FTP.php b/src/Transfer/FTP.php index 6b16781..892e1bb 100644 --- a/src/Transfer/FTP.php +++ b/src/Transfer/FTP.php @@ -4,4 +4,7 @@ namespace Cubist\Net\Transfer; class FTP extends Driver { + public function copy($source, $dest, $mirror = false) { + // TODO: Implement copy() method. + } } \ No newline at end of file diff --git a/src/Transfer/Local.php b/src/Transfer/Local.php index 3bab3cf..3d8b5f5 100644 --- a/src/Transfer/Local.php +++ b/src/Transfer/Local.php @@ -2,6 +2,8 @@ namespace Cubist\Net\Transfer; +use Cubist\Util\CommandLine\Rsync; + class Local extends Driver { protected $_basePath = ''; @@ -25,4 +27,23 @@ class Local extends Driver { public function getBasePath() { return $this->_basePath; } + + /** + * @param $path + * @return string + */ + protected function _destPath($path) { + return rtrim($this->getBasePath(), '/') . '/' . self::_cleanInstallDir($path) . '/'; + } + + public function copy($source, $dest, $mirror = false) { + $destPath = $this->_destPath($dest); + $rsync = new Rsync($source, $destPath); + $rsync->setMirror($mirror); + $rsync->setDryRun(true); + $rsync->execute(); + return $rsync; + } + + } \ No newline at end of file diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index 4037bf9..7b7607f 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -2,6 +2,27 @@ namespace Cubist\Net\Transfer; +use Cubist\Util\CommandLine\Rclone; +use Cubist\Util\CommandLine\Rsync; + class SFTP extends Driver { + public function copy($source, $dest, $mirror = false) { + $server=$this->getServer(); + + $destPath = $this->_destPath($dest); + $rclone = new Rclone(); + $rclone->setProtocol('sftp'); + $rclone->setSrc($source); + $rclone->setDest($destPath); + $rclone->setMirror($mirror); + $rclone->setProtocol('sftp'); + $rclone->addRcloneArg('sftp-host',$server->getHost()); + $rclone->addRcloneArg('sftp-port',$server->getPort()); + $rclone->addRcloneArg('sftp-user',$server->getUsername()); + $rclone->addRcloneArg('sftp-pass',$server->getPassword()); + $rclone->setDryRun(true); + $rclone->execute(); + return $rclone; + } } \ No newline at end of file