{
$lftp = $this->_lftp($source, $dest, $mirror, $dryrun);
$lftp->execute();
+ $lftp->debug();
return $lftp;
}
return self::ERROR_MISSING_HOST;
} else {
$ftp_connect = $this->getServer()->getProtocol() === 'FTP' ? 'ftp_connect' : 'ftp_ssl_connect';
+
try {
$ftp = $ftp_connect($data['host'], $data['port'], 12);
+
} catch (\Exception $e) {
return static::ERROR_INVALID_PARAM;
}
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());
+ $tmp = Files::tempnam(); //on créé un fichier temporaire vide
+ $this->copyFile($tmp, '');
+ unlink($tmp); //on supprime le fichier en local
} 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
+ if ($contents[0] == '213 0') { //on vérifie que le code 213 est présent (ça confirme que le fichier temporaire est bien présent)
ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
- unlink($tmp); //on supprime le fichier en local
- ftp_close($ftp);
+ try {
+ ftp_close($ftp);
+ } catch (\Exception $e) {
+ // Le test n'échoue pas si on n'arrive pas à fermer la connexion FTP
+ }
return true;
} else {
return static::ERROR_SEND_FILE;