From: soufiane Date: Tue, 28 Nov 2023 14:39:30 +0000 (+0100) Subject: wip #6527 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=badaf4bddf35dc1d8c90bb8ed0fa7ddde1491c38;p=cubist_net.git wip #6527 --- diff --git a/src/Transfer/FTP.php b/src/Transfer/FTP.php index 42c7788..472abe1 100644 --- a/src/Transfer/FTP.php +++ b/src/Transfer/FTP.php @@ -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