1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<?php
/*$src_dir = "/from";
$dst_dir = "/to";*/
$conn_id = ftp_connect('www.serveur.com');
$ftp_user_name = 'login';
$ftp_user_pass = 'pass';
//ftp_copy($src_dir, $dst_dir);
//ftp_close($conn_id)
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
function ftp_copy($src_dir, $dst_dir) {
global $conn_id;
$directory = ftp_chdir($conn_id,$src_dir);
$d = dir($directory);
while($file = $d->read()) {
if ($file != "." && $file != "..") {
if (is_dir($directory."/".$file)) {
if (!@ftp_chdir($conn_id, $dst_dir."/".$file)) {
ftp_mkdir($conn_id, $dst_dir."/".$file);
}
ftp_copy($directory."/".$file, $dst_dir."/".$file);
}
else {
$upload = ftp_put($conn_id, $dst_dir."/".$file, $directory."/".$file, FTP_BINARY);
}
}
}
$d->close();
}
if($_POST['envoyer']){
$dir=$_POST['dirname'];
if (ftp_mkdir($conn_id, 'www/'.$dir)) {
echo "Le dossier $dir a été créé avec succès\n";
$origine = "www/copydir";
$destination = "www/".$dir."/";
if(ftp_copy($origine, $destination)) {
echo "Le dossier ".$origine." a ete copie avec succes vers ".$destination;
}else{
echo "copie echouée";
}
}
}
?> |
Partager