abstract protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false);
- /**
+ /**
* @param $source string
* @param $dest string
* @param $mirror bool
* @param $dryrun bool
* @return CommandLine
*/
- 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 copy($source, $dest, $mirror = false, $dryrun = false)
+ {
+ if ($this->checkConnexion() !== true) {
+ throw new \Exception('Unabled to connect to this server (error code : ' . $this->checkConnexion() . ' )');
}
return $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
}
use Cubist\Util\CommandLine\LFTP;
use Cubist\Util\Files\Files;
-class FTP extends Driver {
+class FTP extends Driver
+{
const ERROR_MISSING_HOST = 0;
protected $port = 21;
- protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+ protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false)
+ {
$lftp = new LFTP();
$lftp->setServer($this->getServer());
$lftp->setSrc($source);
return $lftp;
}
- public function checkConnexion($data = []) {
+ public function checkConnexion($data = [])
+ {
$data['port'] = $data['port'] ?? $this->port;
$data = [
'username' => $data['username'] ?? $this->getServer()->getUsername(),
'password' => $data['password'] ?? $this->getServer()->getPassword(),
'host' => $data['host'] ?? $this->getServer()->getHost(),
- 'port' => array_key_exists('port',$data) ? $data['port'] : $this->getServer()->getPort(),
+ 'port' => array_key_exists('port', $data) ? $data['port'] : $this->getServer()->getPort(),
];
- if(!$data['host']) {
+ if (!$data['host']) {
return self::ERROR_MISSING_HOST;
} else {
try {
$ftp = $data['port'] ? ftp_connect($data['host'], $data['port']) : ftp_connect($data['host']);
- } catch(\Exception $e) {
+ } catch (\Exception $e) {
return static::ERROR_INVALID_PARAM;
}
- if($ftp) {
+ if ($ftp) {
if (@ftp_login($ftp, $data['username'], $data['password'])) {
try {
$tmp = Files::tempnam(); //on créé un fichier temporaire
- $this->copyFile($tmp,$this->getServer()->getBasePath());
- } catch(\Exception $e) {
+ $this->copyFile($tmp, $this->getServer()->getBasePath());
+ } catch (\Exception $e) {
return static::ERROR_SEND_FILE;
}
- $file = $this->getServer()->getBasePath().$this->getTestFilename($tmp);
+ $file = $this->getServer()->getBasePath() . $this->getTestFilename($tmp);
$contents = ftp_raw($ftp, "SIZE $file");
- if(strstr($contents[0],"213")) { //on vérifie si le code 213 est présent
+ if (strstr($contents[0], "213")) { //on vérifie si le code 213 est présent
ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
unlink($tmp); //on supprime le fichier en local
ftp_close($ftp);
}
- public function getTestFilename($file) {
- $filepath = explode('/',$file);
+ public function getTestFilename($file)
+ {
+ $filepath = explode('/', $file);
return end($filepath);
}
}
\ No newline at end of file