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;
// 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