]> _ Git - cubist_net.git/commitdiff
wip #6527
authorsoufiane <soufiane@cubedesigners.com>
Tue, 28 Nov 2023 14:39:30 +0000 (15:39 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 28 Nov 2023 14:39:30 +0000 (15:39 +0100)
src/Transfer/FTP.php

index 42c778897ec6933e36c606450c5fad1a2076e7d1..472abe1abf84e249677ebcc1128d9d26d109771d 100644 (file)
@@ -6,7 +6,12 @@ use Cubist\Util\CommandLine\LFTP;
 use Cubist\Util\CommandLine\Rclone;
 
 class FTP extends Driver {
-    const SUCCESS = 0;
+
+    const ERROR_MISSING_HOST = 0;
+
+    const ERROR_INVALID_PARAM = 1;
+
+    const ERROR_CONNEXION_FAILED = 2;
 
     const ERROR_PROTOCOL_NOT_READY = 4;
 
@@ -29,7 +34,33 @@ class FTP extends Driver {
         // TODO: Implement copyFile() method.
     }
 
-    public function checkConnexion() {
-        return static::ERROR_PROTOCOL_NOT_READY;
+    public function checkConnexion($data = []) {
+
+        $data = [
+            'username' => $data['username'] ?? $this->getServer()->getUsername(),
+            'password' => $data['password'] ?? $this->getServer()->getPassword(),
+            'host' => $data['host'] ?? $this->getServer()->getHost(),
+            'port' => $data['port'],
+        ];
+
+        if(!$data['host']) {
+            return self::ERROR_MISSING_HOST;
+        } else {
+            // Mise en place d'une connexion basique
+            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);
+            }
+
+            // Tentative d'identification
+            if (@ftp_login($ftp, $data['username'], $data['password'])) {
+                ftp_close($ftp);
+                return true;
+            } else {
+                return static::ERROR_CONNEXION_FAILED;
+            }
+        }
+
     }
 }
\ No newline at end of file