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() .' )');
public function checkConnexion($data = []) {
+ $data['port'] = $data['port'] ?? $this->port;
$data = [
'username' => $data['username'] ?? $this->getServer()->getUsername(),
'password' => $data['password'] ?? $this->getServer()->getPassword(),
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;
}
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() .' )');
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(),