]> _ Git - cubist_net.git/commitdiff
wait #6527 @0:30
authorsoufiane <soufiane@cubedesigners.com>
Thu, 30 Nov 2023 16:25:40 +0000 (17:25 +0100)
committersoufiane <soufiane@cubedesigners.com>
Thu, 30 Nov 2023 16:25:40 +0000 (17:25 +0100)
src/Transfer/FTP.php
src/Transfer/SFTP.php

index 605a90d437affaa6fd350b2ac62c2623b8fda342..ddb3e606f275d23ba8facb43587ee99dd78d3a0e 100644 (file)
@@ -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;
             }
index e2fcdf526e14e38a4a94f9ca3119a34ebd7898ff..64163cbe4205c7c62719c2f5c41ce058023bd4fa 100644 (file)
@@ -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(),