From: Vincent Vanwaelscappel Date: Thu, 18 Apr 2024 13:13:29 +0000 (+0200) Subject: wait #6869 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=567cca471663e483d0e3cfbd12fe8126a200b017;p=cubist_net.git wait #6869 @0.5 --- diff --git a/src/Transfer/Driver.php b/src/Transfer/Driver.php index bbd36f3..c096783 100644 --- a/src/Transfer/Driver.php +++ b/src/Transfer/Driver.php @@ -48,6 +48,8 @@ abstract class Driver return self::cleanInstallDir($path); } + abstract public function checkConnexion($data = []); + abstract protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false); /** diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index 4c33773..668e99d 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -4,8 +4,10 @@ namespace Cubist\Net\Transfer; use Cubist\Util\CommandLine\Rclone; use Cubist\Util\Files\Files; +use Illuminate\Support\Facades\Log; -class SFTP extends Driver { +class SFTP extends Driver +{ const ERROR_MISSING_HOST = 0; @@ -15,9 +17,10 @@ class SFTP extends Driver { const ERROR_SEND_FILE = 5; - protected $port = 22; + const DEFAULT_PORT = 22; - protected 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 +30,19 @@ class SFTP extends Driver { $rclone->execute(); return $rclone; } - - public function checkConnexion($data = []) { + + public function checkConnexion($data = []) + { $connection = null; - $data['port'] = $data['port'] ?? $this->port; $data = [ 'username' => $data['username'] ?? $this->getServer()->getUsername(), 'password' => $data['password'] ?? $this->getServer()->getPassword(), 'host' => $data['host'] ?? $this->getServer()->getHost(), - 'port' => $data['port'] ?? $this->getServer()->getPort(), + 'port' => $data['port'] ?? $this->getServer()->getPort() ?? self::DEFAULT_PORT, ]; - if(!$data['host']) { + if (!$data['host']) { return self::ERROR_MISSING_HOST; } else { try { @@ -55,30 +58,31 @@ class SFTP extends Driver { } try { - $tmp = Files::tempnam("/application"); //on créé un fichier temporaire en local + $tmp = Files::tempnam(); //on créé un fichier temporaire en local $this->copyFile($tmp, '/'); - } catch(\Exception $e) { + } catch (\Exception $e) { return static::ERROR_SEND_FILE; } try { $filename = $this->getTestFilename($tmp); $sftp = ssh2_sftp($connection); - $basepath = '/'.trim($this->getServer()->getBasePath(), '/').'/'; - $f = @ssh2_sftp_stat($sftp, $basepath.$filename); - ssh2_sftp_unlink($sftp, $basepath.$filename); //on supprime le fichier distant + $basepath = '/' . trim($this->getServer()->getBasePath(), '/') . '/'; + $f = @ssh2_sftp_stat($sftp, $basepath . $filename); + ssh2_sftp_unlink($sftp, $basepath . $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) { + } catch (\Exception $e) { return static::ERROR_SEND_FILE; } } } - public function getTestFilename($file) { - $filepath = explode('/',$file); + public function getTestFilename($file) + { + $filepath = explode('/', $file); return end($filepath); } } \ No newline at end of file