From 219a0559058cba8664271692b474cd412a2d498d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 12 Feb 2025 12:08:35 +0100 Subject: [PATCH] wip #7328 @0.5 --- src/Transfer/FTP.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Transfer/FTP.php b/src/Transfer/FTP.php index 5194646..ddd9354 100644 --- a/src/Transfer/FTP.php +++ b/src/Transfer/FTP.php @@ -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; -- 2.39.5