From: soufiane Date: Thu, 1 Feb 2024 15:16:16 +0000 (+0100) Subject: wait #6668 @1:30 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2ce0039849af4c8a877c81e57f5fb7568541bf8e;p=cubist_net.git wait #6668 @1:30 --- diff --git a/src/Transfer/Driver.php b/src/Transfer/Driver.php index 33be5eb..bbd36f3 100644 --- a/src/Transfer/Driver.php +++ b/src/Transfer/Driver.php @@ -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 diff --git a/src/Transfer/FTP.php b/src/Transfer/FTP.php index e1ea65d..ab2b385 100644 --- a/src/Transfer/FTP.php +++ b/src/Transfer/FTP.php @@ -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 diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index d07f02d..a1160ad 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -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;