////////////////////////////////////////////////////////
// Copy directory to directory with all sub-directory and files using FTP
// By:
// Ahmed Samir
// asamir@asamir.net
// www.asamir.net
//
////////////////////////////////////////////////////////
function ftp_copyAll($conn_id, $src_dir, $dst_dir) {
if(is_dir($dst_dir)){
return "
Dir $dst_dir Already exists
";
}else{
$d = dir($src_dir);
ftp_mkdir($conn_id, $dst_dir); echo "creat dir $dst_dir
";
while($file = $d->read()) { // do this for each file in the directory
if ($file != "." && $file != "..") { // to prevent an infinite loop
if (is_dir($src_dir."/".$file)) { // do the following if it is a directory
ftp_copyAll($conn_id, $src_dir."/".$file, $dst_dir."/".$file); // recursive part
} else {
$upload = ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY); // put the files
echo "creat files::: ".$dst_dir."/".$file ."
";
}
}
ob_flush() ;
sleep(1);
}
$d->close();
}
return "
All Copied ok ";
} // end fn function ftp_copyAll
//$ftp_user_name = 'asamirftp@phpeg.net';
//$ftp_user_pass = 'asamirftp123';
//$ftp_server = 'phpeg.net';
// connect to FTP server
$ftp_user_name = 'FTP_User_name';
$ftp_user_pass = 'FTP_Password';
$ftp_server = 'FTP_Server';
$conn_id = @ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// login into FTP server
if (@ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) {
//echo "Connected as $ftp_user_name@$ftp_server\n";
ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 1000); // Set the network timeout to 10 seconds
$copy_result = ftp_copyAll($conn_id, 'Folder', 'FolderCopy');
echo $copy_result;
}else{
echo "Couldn't connect as $ftp_user\n";
}
@ftp_close($conn_id); // colse of ftp_connect
// @ftp_quit($conn_id);
?>
Thursday, May 22, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment