From b91a2ea5f9b5a1b7f8fcff41dab3acf2b895fe29 Mon Sep 17 00:00:00 2001 From: soufiane Date: Thu, 30 Nov 2023 17:25:40 +0100 Subject: [PATCH] wait #6527 @0:30 --- src/Transfer/FTP.php | 21 ++++++++++++++------- src/Transfer/SFTP.php | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Transfer/FTP.php b/src/Transfer/FTP.php index 605a90d..ddb3e60 100644 --- a/src/Transfer/FTP.php +++ b/src/Transfer/FTP.php @@ -15,6 +15,8 @@ class FTP extends Driver { const ERROR_PROTOCOL_NOT_READY = 4; + protected $port = 21; + 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() .' )'); @@ -36,6 +38,7 @@ class FTP extends Driver { public function checkConnexion($data = []) { + $data['port'] = $data['port'] ?? $this->port; $data = [ 'username' => $data['username'] ?? $this->getServer()->getUsername(), 'password' => $data['password'] ?? $this->getServer()->getPassword(), @@ -46,15 +49,19 @@ class FTP extends Driver { if(!$data['host']) { return self::ERROR_MISSING_HOST; } else { - if($data['port'] !== 22) { - $ftp = ftp_connect($data['host'], $data['port']) or die(static::ERROR_INVALID_PARAM); - } else { - $ftp = ftp_connect($data['host']) or die(static::ERROR_INVALID_PARAM); + try { + $ftp = $data['port'] ? ftp_connect($data['host'], $data['port']) : ftp_connect($data['host']); + } catch(\Exception $e) { + return static::ERROR_INVALID_PARAM; } - if (@ftp_login($ftp, $data['username'], $data['password'])) { - ftp_close($ftp); - return true; + if($ftp) { + if (@ftp_login($ftp, $data['username'], $data['password'])) { + ftp_close($ftp); + return true; + } else { + return static::ERROR_CONNEXION_FAILED; + } } else { return static::ERROR_CONNEXION_FAILED; } diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index e2fcdf5..64163cb 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -12,6 +12,8 @@ class SFTP extends Driver { const ERROR_CONNEXION_FAILED = 2; + protected $port = 22; + 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() .' )'); @@ -34,6 +36,7 @@ class SFTP extends Driver { 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(), -- 2.39.5