return self::cleanInstallDir($path);
}
- /**
+ abstract protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false);
+
+ /**
* @param $source string
* @param $dest string
* @param $mirror bool
* @param $dryrun bool
* @return CommandLine
*/
- abstract public function copy($source, $dest, $mirror = false, $dryrun = false);
+ 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);
+ }
- abstract public function copyFile($source, $dest);
+ public function copyFile($source, $dest)
+ {
+ return $this->synchronizeFiles($source, $dest);
+ }
}
\ No newline at end of file
protected $port = 21;
- public 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 copy($source, $dest, $mirror = false, $dryrun = false) {
- if($this->checkConnexion() !== true) {
- throw new \Exception('Unabled to connect to this server (error code : '. $this->checkConnexion() .' )');
- }
- $this->synchronizeFiles($source, $dest);
- }
-
- public function copyFile($source, $dest)
- {
- $this->synchronizeFiles($source, $dest);
- }
-
public function checkConnexion($data = []) {
$data['port'] = $data['port'] ?? $this->port;
if (@ftp_login($ftp, $data['username'], $data['password'])) {
try {
$tmp = Files::tempnam(); //on créé un fichier temporaire
- $this->copyFile($tmp,self::cleanInstallDir('/'). '/');
- unlink($tmp); //on supprime le fichier
+ $this->copyFile($tmp,$this->getServer()->getBasePath());
+ } catch(\Exception $e) {
+ return static::ERROR_SEND_FILE;
+ }
+
+ $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
+ ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
+ unlink($tmp); //on supprime le fichier en local
ftp_close($ftp);
return true;
- } catch(\Exception $e) {
+ } else {
return static::ERROR_SEND_FILE;
}
} else {
}
}
+
+ public function getTestFilename($file) {
+ $filepath = explode('/',$file);
+ return end($filepath);
+ }
}
\ No newline at end of file
protected $port = 22;
- public function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+ protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
$rclone = new Rclone();
$rclone->setServer($this->getServer());
$rclone->setSrc($source);
$rclone->execute();
return $rclone;
}
-
- 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() .' )');
- }
- $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
- }
-
- public function copyFile($source, $dest)
- {
- return $this->synchronizeFiles($source, $dest);
- }
-
+
public function checkConnexion($data = []) {
$connection = null;