]> _ Git - cubist_net.git/commitdiff
wip #7328 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Feb 2025 11:08:35 +0000 (12:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Feb 2025 11:08:35 +0000 (12:08 +0100)
src/Transfer/FTP.php

index 51946468bb3c6bde646f23d81bcba70902189e1b..ddd9354f9b055ffa2f287f0bcf8276388a217d18 100644 (file)
@@ -42,6 +42,7 @@ class FTP extends Driver
     {
         $lftp = $this->_lftp($source, $dest, $mirror, $dryrun);
         $lftp->execute();
+        $lftp->debug();
         return $lftp;
     }
 
@@ -62,8 +63,10 @@ class FTP extends Driver
             return self::ERROR_MISSING_HOST;
         } else {
             $ftp_connect = $this->getServer()->getProtocol() === 'FTP' ? 'ftp_connect' : 'ftp_ssl_connect';
+
             try {
                 $ftp = $ftp_connect($data['host'], $data['port'], 12);
+
             } catch (\Exception $e) {
                 return static::ERROR_INVALID_PARAM;
             }
@@ -71,18 +74,22 @@ class FTP extends Driver
             if ($ftp) {
                 if (@ftp_login($ftp, $data['username'], $data['password'])) {
                     try {
-                        $tmp = Files::tempnam(); //on créé un fichier temporaire
-                        $this->copyFile($tmp, $this->getServer()->getBasePath());
+                        $tmp = Files::tempnam(); //on créé un fichier temporaire vide
+                        $this->copyFile($tmp, '');
+                        unlink($tmp); //on supprime le fichier en local
                     } 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
+                    if ($contents[0] == '213 0') { //on vérifie que le code 213 est présent (ça confirme que le fichier temporaire est bien présent)
                         ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
-                        unlink($tmp); //on supprime le fichier en local
-                        ftp_close($ftp);
+                        try {
+                            ftp_close($ftp);
+                        } catch (\Exception $e) {
+                            // Le test n'échoue pas si on n'arrive pas à fermer la connexion FTP
+                        }
                         return true;
                     } else {
                         return static::ERROR_SEND_FILE;