]> _ Git - cubist_net.git/commitdiff
wait #6668 @1:30
authorsoufiane <soufiane@cubedesigners.com>
Thu, 1 Feb 2024 15:16:16 +0000 (16:16 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 1 Feb 2024 15:16:16 +0000 (16:16 +0100)
src/Transfer/Driver.php
src/Transfer/FTP.php
src/Transfer/SFTP.php

index 33be5eb851c9e9f52d214e74c7e12aac92675cc3..bbd36f3b193f42cae11b91d5e694cd8296557848 100644 (file)
@@ -48,14 +48,24 @@ abstract class Driver
         return self::cleanInstallDir($path);
     }
 
-    /**
+    abstract protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false);
+
+        /**
      * @param $source string
      * @param $dest string
      * @param $mirror bool
      * @param $dryrun bool
      * @return CommandLine
      */
-    abstract public function copy($source, $dest, $mirror = false, $dryrun = false);
+    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() .' )');
+        }
+        return $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
+    }
 
-    abstract public function copyFile($source, $dest);
+    public function copyFile($source, $dest)
+    {
+        return $this->synchronizeFiles($source, $dest);
+    }
 }
\ No newline at end of file
index e1ea65dd618690ec252159ba08b9a7019f74b9e5..ab2b3855689b4dc3c5d08b91b8b3bc4ef4bb876c 100644 (file)
@@ -19,7 +19,7 @@ class FTP extends Driver {
 
     protected $port = 21;
 
-    public function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+    protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
         $lftp = new LFTP();
         $lftp->setServer($this->getServer());
         $lftp->setSrc($source);
@@ -30,18 +30,6 @@ class FTP extends Driver {
         return $lftp;
     }
 
-       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() .' )');
-        }
-        $this->synchronizeFiles($source, $dest);
-       }
-
-    public function copyFile($source, $dest)
-    {
-        $this->synchronizeFiles($source, $dest);
-    }
-
     public function checkConnexion($data = []) {
 
         $data['port'] = $data['port'] ?? $this->port;
@@ -65,11 +53,19 @@ class FTP extends Driver {
                 if (@ftp_login($ftp, $data['username'], $data['password'])) {
                     try {
                         $tmp = Files::tempnam(); //on créé un fichier temporaire
-                        $this->copyFile($tmp,self::cleanInstallDir('/'). '/');
-                        unlink($tmp); //on supprime le fichier
+                        $this->copyFile($tmp,$this->getServer()->getBasePath());
+                    } catch(\Exception $e) {
+                        return static::ERROR_SEND_FILE;
+                    }
+
+                    $file = $this->getServer()->getBasePath().$this->getTestFilename($tmp);
+                    $contents = ftp_raw($ftp, "SIZE $file");
+                    if(strstr($contents[0],"213")) { //on vérifie si le code 213 est présent
+                        ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
+                        unlink($tmp); //on supprime le fichier en local
                         ftp_close($ftp);
                         return true;
-                    } catch(\Exception $e) {
+                    } else {
                         return static::ERROR_SEND_FILE;
                     }
                 } else {
@@ -81,4 +77,9 @@ class FTP extends Driver {
         }
 
     }
+
+    public function getTestFilename($file) {
+        $filepath = explode('/',$file);
+        return end($filepath);
+    }
 }
\ No newline at end of file
index d07f02d1594ba6d1f02b0453052bd409d0088f42..a1160ad9d848650bfae6f1152e70536262ef8ca6 100644 (file)
@@ -17,7 +17,7 @@ class SFTP extends Driver {
 
     protected $port = 22;
 
-    public function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+    protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
         $rclone = new Rclone();
         $rclone->setServer($this->getServer());
         $rclone->setSrc($source);
@@ -27,19 +27,7 @@ class SFTP extends Driver {
         $rclone->execute();
         return $rclone;
     }
-
-       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() .' )');
-        }
-               $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
-       }
-
-    public function copyFile($source, $dest)
-    {
-        return $this->synchronizeFiles($source, $dest);
-    }
-
+    
     public function checkConnexion($data = []) {
         $connection = null;