File "ftp01.php"
Full Path: /home/analogde/www/MDPH/FTP/ftp01.php
File size: 1.12 KB
MIME-type: text/x-php
Charset: utf-8
<?php
function uploadDirectory($localDir, $ftpDir, $ftpConn)
{
if ($dirHandle = opendir($localDir))
{
while (false !== ($file = readdir($dirHandle))) {
if ($file != '.' && $file != '..') {
$localFile = $localDir . '/' . $file;
$ftpFile = $ftpDir . '/' . $file;
if (is_dir($localFile)) {
if (!@ftp_chdir($ftpConn, $ftpFile)) {
ftp_mkdir($ftpConn, $ftpFile);
}
uploadDirectory($localFile, $ftpFile, $ftpConn);
} else {
ftp_put($ftpConn, $ftpFile, $localFile, FTP_BINARY);
}
}
}
closedir($dirHandle);
}
}
$ftpServer = 'ftp.votre-serveur.com';
$ftpUser = 'votre-utilisateur';
$ftpPass = 'votre-mot-de-passe';
$localDir = '/chemin/vers/repertoire/local';
$ftpDir = '/chemin/vers/repertoire/distant';
$ftpConn = ftp_connect($ftpServer);
ftp_login($ftpConn, $ftpUser, $ftpPass);
uploadDirectory($localDir, $ftpDir, $ftpConn);
ftp_close($ftpConn);
echo "Le répertoire a été copié avec succès.";
?>