use Cubist\Util\CommandLine\Rclone;
class FTP extends Driver {
+ const SUCCESS = 0;
+
+ const ERROR_PROTOCOL_NOT_READY = 4;
+
public function copy($source, $dest, $mirror = false, $dryrun = false) {
+ if($this->checkConnexion() !== true) {
+ throw new \Exception('Unabled to connect to this server (error code : '. $this->checkConnexion() .' )');
+ }
$lftp = new LFTP();
$lftp->setServer($this->getServer());
$lftp->setSrc($source);
{
// TODO: Implement copyFile() method.
}
+
+ public function checkConnexion() {
+ return static::ERROR_PROTOCOL_NOT_READY;
+ }
}
\ No newline at end of file
{
protected $_rootPath = '';
+ const ERROR_FOLDER_UNMOUNT = 3;
+
public function __construct(IServer $server, $rootPath = null)
{
parent::__construct($server);
public function copy($source, $dest, $mirror = false, $dryrun = false)
{
+ if($this->checkConnexion() !== true) {
+ throw new \Exception('Unabled to connect to this server (error code : '. $this->checkConnexion() .' )');
+ }
$rsync = new Rsync($source, $dest);
$rsync->setServer($this->getServer());
$rsync->setBasePath($this->_basePath());
return copy($source, $this->_basePath() . '/' . $dest);
}
+ public function checkConnexion($data = []) {
+ if(file_exists($this->getRootPath().'status')) {
+ return true;
+ } else {
+ return static::ERROR_FOLDER_UNMOUNT;
+ }
+ }
}
\ No newline at end of file
class SFTP extends Driver {
+ const ERROR_MISSING_HOST = 0;
+
+ const ERROR_INVALID_PARAM = 1;
+
+ const ERROR_CONNEXION_FAILED = 2;
+
public function copy($source, $dest, $mirror = false, $dryrun = false) {
+ if($this->checkConnexion() !== true) {
+ throw new \Exception('Unabled to connect to this server (error code : '. $this->checkConnexion() .' )');
+ }
$rclone = new Rclone();
$rclone->setServer($this->getServer());
$rclone->setSrc($source);
{
// TODO: Implement copyFile() method.
}
+
+ public function checkConnexion($data = []) {
+ $connection = null;
+
+ $data = [
+ 'username' => $data['username'] ?? $this->getServer()->getUsername(),
+ 'password' => $data['password'] ?? $this->getServer()->getPassword(),
+ 'host' => $data['host'] ?? $this->getServer()->getHost(),
+ 'port' => $data['port'] ?? $this->getServer()->getPort(),
+ ];
+
+ if(!$data['host']) {
+ return self::ERROR_MISSING_HOST;
+ } else {
+ try {
+ $connection = ssh2_connect($data['host'], $data['port']);
+ } catch (\Exception $e) {
+ return static::ERROR_INVALID_PARAM;
+ }
+
+ try {
+ ssh2_auth_password($connection, $data['username'], $data['password']);
+ ssh2_disconnect($connection);
+ return true;
+ } catch (\Exception $e) {
+ return static::ERROR_CONNEXION_FAILED;
+ }
+
+ }
+ }
}
\ No newline at end of file