]> _ Git - cubist_net.git/commitdiff
wip #6668 @3:00
authorsoufiane <soufiane@cubedesigners.com>
Wed, 31 Jan 2024 14:58:02 +0000 (15:58 +0100)
committersoufiane <soufiane@cubedesigners.com>
Wed, 31 Jan 2024 14:58:02 +0000 (15:58 +0100)
src/Transfer/SFTP.php

index 4a7ade6911a22624c0732547d74084f234c58012..d07f02d1594ba6d1f02b0453052bd409d0088f42 100644 (file)
@@ -37,7 +37,7 @@ class SFTP extends Driver {
 
     public function copyFile($source, $dest)
     {
-        $this->synchronizeFiles($source, $dest);
+        return $this->synchronizeFiles($source, $dest);
     }
 
     public function checkConnexion($data = []) {
@@ -62,19 +62,34 @@ class SFTP extends Driver {
 
             try {
                 ssh2_auth_password($connection, $data['username'], $data['password']);
-                try {
-                    $tmp = Files::tempnam(); //on créé un fichier temporaire
-                    $this->copyFile($tmp,self::cleanInstallDir('/'). '/');
-                    unlink($tmp); //on supprime le fichier
-                    ssh2_disconnect($connection);
-                    return true;
-                } catch(\Exception $e) {
-                    return static::ERROR_SEND_FILE;
-                }
             } catch (\Exception $e) {
                 return static::ERROR_CONNEXION_FAILED;
             }
 
+            try {
+                $tmp = Files::tempnam("/application"); //on créé un fichier temporaire en local
+                $this->copyFile($tmp, '/');
+            } catch(\Exception $e) {
+                return static::ERROR_SEND_FILE;
+            }
+
+            try {
+                $filename = $this->getTestFilename($tmp);
+                $sftp = ssh2_sftp($connection);
+                fopen("ssh2.sftp://".intval($sftp).$this->getServer()->getBasePath().$filename, 'r'); //on vérifie l'existance du fichier distant
+                ssh2_sftp_unlink($sftp, $this->getServer()->getBasePath().$filename); //on supprime le fichier distant
+                ssh2_disconnect($connection); //on quitte la connexion
+                unlink($tmp); //on supprime le fichier temporaire en local
+                return true;
+            } catch(\Exception $e) {
+                return static::ERROR_SEND_FILE;
+            }
+
         }
     }
+
+    public function getTestFilename($file) {
+        $filepath = explode('/',$file);
+        return end($filepath);
+    }
 }
\ No newline at end of file