From e073d70e75274fb0013e0e80ac525780678ef4ca Mon Sep 17 00:00:00 2001 From: soufiane Date: Wed, 31 Jan 2024 15:58:02 +0100 Subject: [PATCH] wip #6668 @3:00 --- src/Transfer/SFTP.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index 4a7ade6..d07f02d 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -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 -- 2.39.5