public function copyFile($source, $dest)
{
- $this->synchronizeFiles($source, $dest);
+ return $this->synchronizeFiles($source, $dest);
}
public function checkConnexion($data = []) {
try {
ssh2_auth_password($connection, $data['username'], $data['password']);
- 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;
}
+ try {
+ $tmp = Files::tempnam("/application"); //on créé un fichier temporaire en local
+ $this->copyFile($tmp, '/');
+ } catch(\Exception $e) {
+ return static::ERROR_SEND_FILE;
+ }
+
+ try {
+ $filename = $this->getTestFilename($tmp);
+ $sftp = ssh2_sftp($connection);
+ fopen("ssh2.sftp://".intval($sftp).$this->getServer()->getBasePath().$filename, 'r'); //on vérifie l'existance du fichier distant
+ ssh2_sftp_unlink($sftp, $this->getServer()->getBasePath().$filename); //on supprime le fichier distant
+ ssh2_disconnect($connection); //on quitte la connexion
+ unlink($tmp); //on supprime le fichier temporaire en local
+ return true;
+ } catch(\Exception $e) {
+ return static::ERROR_SEND_FILE;
+ }
+
}
}
+
+ public function getTestFilename($file) {
+ $filepath = explode('/',$file);
+ return end($filepath);
+ }
}
\ No newline at end of file