],
"require": {
"php": ">=5.4.0",
- "ext-ssh2": "*"
+ "ext-ssh2": "*",
+ "cubist/util": "dev-master"
+ },
+ "suggest": {
+
}
}
namespace Cubist\Net\Transfer;
-class Driver {
+use Cubist\Util\CommandLine;
+use Cubist\Util\Text;
+
+abstract class Driver {
/**
* @var IServer
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
class FTP extends Driver {
+ public function copy($source, $dest, $mirror = false) {
+ // TODO: Implement copy() method.
+ }
}
\ No newline at end of file
namespace Cubist\Net\Transfer;
+use Cubist\Util\CommandLine\Rsync;
+
class Local extends Driver {
protected $_basePath = '';
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
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