]> _ Git - cubist_net.git/commitdiff
wip #5700 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 07:49:39 +0000 (08:49 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 27 Jan 2023 07:49:39 +0000 (08:49 +0100)
composer.json
src/Transfer/Driver.php
src/Transfer/FTP.php
src/Transfer/Local.php
src/Transfer/SFTP.php

index 530dc199b538b9ac7565ced3d660b6dd8965f83c..274046b3494577273e607a750c6caf6a13e3dc48 100644 (file)
   ],
   "require": {
     "php": ">=5.4.0",
-    "ext-ssh2": "*"
+    "ext-ssh2": "*",
+    "cubist/util": "dev-master"
+  },
+  "suggest": {
+
   }
 }
index 29f00a0bcaa6c9ce1f283f770b460ac344e155ec..caa42e86102b9d159c8d1e8e5213009a50f8bab3 100644 (file)
@@ -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
index 6b16781bf809eccc83fb5dd06ce9e4bd73d83be2..892e1bba07dd38b1a34c0bb7c000303da7304f8d 100644 (file)
@@ -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
index 3bab3cfe693630410d739df4cdc34ff9a2f8f57a..3d8b5f5b48e758835d7d248e2c0f8704d928341f 100644 (file)
@@ -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
index 4037bf9d39fa674ba33ac94cf73b5faf2c1aa590..7b7607fabe03ef94dc5c6bb90129fdfaa666a3db 100644 (file)
@@ -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