use Cubist\Util\CommandLine\LFTP;
use Cubist\Util\CommandLine\Rclone;
+use Cubist\Util\Files\Files;
class FTP extends Driver {
const ERROR_PROTOCOL_NOT_READY = 4;
+ const ERROR_SEND_FILE = 5;
+
protected $port = 21;
+ public function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+ $lftp = new LFTP();
+ $lftp->setServer($this->getServer());
+ $lftp->setSrc($source);
+ $lftp->setDest($dest);
+ $lftp->setMirror($mirror);
+ $lftp->setDryRun($dryrun);
+ $lftp->execute();
+ 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() .' )');
}
- $lftp = new LFTP();
- $lftp->setServer($this->getServer());
- $lftp->setSrc($source);
- $lftp->setDest($dest);
- $lftp->setMirror($mirror);
- $lftp->setDryRun($dryrun);
- $lftp->execute();
- return $lftp;
+ $this->synchronizeFiles($source, $dest);
}
public function copyFile($source, $dest)
{
- // TODO: Implement copyFile() method.
+ $this->synchronizeFiles($source, $dest);
}
public function checkConnexion($data = []) {
if($ftp) {
if (@ftp_login($ftp, $data['username'], $data['password'])) {
- ftp_close($ftp);
- return true;
+ try {
+ $tmp = Files::tempnam(); //on créé un fichier temporaire
+ $this->copyFile($tmp,self::cleanInstallDir('/'). '/');
+ unlink($tmp); //on supprime le fichier
+ ftp_close($ftp);
+ return true;
+ } catch(\Exception $e) {
+ return static::ERROR_SEND_FILE;
+ }
} else {
return static::ERROR_CONNEXION_FAILED;
}
return static::ERROR_CONNEXION_FAILED;
}
}
-
}
}
\ No newline at end of file
namespace Cubist\Net\Transfer;
use Cubist\Util\CommandLine\Rclone;
+use Cubist\Util\Files\Files;
class SFTP extends Driver {
const ERROR_CONNEXION_FAILED = 2;
+ const ERROR_SEND_FILE = 5;
+
protected $port = 22;
+ public function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+ $rclone = new Rclone();
+ $rclone->setServer($this->getServer());
+ $rclone->setSrc($source);
+ $rclone->setDest(rtrim($this->getServer()->getBasePath(), '/') . '/' . trim($dest, '/') . '/');
+ $rclone->setMirror($mirror);
+ $rclone->setDryRun($dryrun);
+ $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() .' )');
}
- $rclone = new Rclone();
- $rclone->setServer($this->getServer());
- $rclone->setSrc($source);
- $rclone->setDest(rtrim($this->getServer()->getBasePath(), '/') . '/' . trim($dest, '/') . '/');
- $rclone->setMirror($mirror);
- $rclone->setDryRun($dryrun);
- $rclone->execute();
- return $rclone;
+ $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
}
public function copyFile($source, $dest)
{
- // TODO: Implement copyFile() method.
+ $this->synchronizeFiles($source, $dest);
}
public function checkConnexion($data = []) {
try {
ssh2_auth_password($connection, $data['username'], $data['password']);
- ssh2_disconnect($connection);
- return true;
+ try {
+ $tmp = Files::tempnam(); //on créé un fichier temporaire
+ $this->copyFile($tmp,self::cleanInstallDir('/'). '/');
+ unlink($tmp); //on supprime le fichier
+ ssh2_disconnect($connection);
+ return true;
+ } catch(\Exception $e) {
+ return static::ERROR_SEND_FILE;
+ }
} catch (\Exception $e) {
return static::ERROR_CONNEXION_FAILED;
}