Hi all and good PHP programming
I have create a script that transfer data with ftp function to local folder
on a remote server.
I have create a recursive function that read all data on local folder and execute the copy. When i transfer data for little kb the script can be able to copy the data with the same path of local folder e.g C:\\back-up\folder1\file.txt
copy to /httpdocs/folder1/file.txt it's ok.
But when the filesize is MB the recursive function is much more speed to read
that write data and the file not is located on the same hierarchy of local folder.
THis is the script :

$user = "user";
$pasw = "pasw";
$ftp_server = "ftp.mydomain.xx";
$mode = "FTP_BINARY";
$remote_folder = "/httpdocs";

function ftp_connection() {

global $user, $pasw, $ftp_server;

$conn = @ftp_connect($ftp_server);
$login = @ftp_login($conn, $user, $pasw);

if((!$conn)||(!$login)) {
die("Cannot open connect with $ftp_server\n");
else {
return $conn;

$conn = ftp_connection();
if(!(@ftp_chdir($conn, $remote_folder)))
die("Cannot to change data folder\n");

function recursive_dir($dir){

#Get ID connect ftp_mode and
global $mode, $conn, $remote_folder;
#Open resource to read data
if (!($handle = @opendir($dir)))
die("Cannot open datadir\n");
#Read data from local folder $default_dir
while(false !==($item = @readdir($handle))){

if (is_dir($dir."/".$item)) {
#Erase al "." and ".." to content of $item
if ($item != "." && $item != ".."){
#Make directory on remote Server
if (!(@ftp_mkdir($conn, $item)))
die("Cannot possible mkdir $item\n");
#Get current directory for current session
$pwd = @ftp_pwd($conn);
if(!$pwd) die("Cannot get current Work Directory\n");

if(!(@ftp_chdir($conn, $pwd."/".$item)))
die("Cannot change directory:".$pwd."/".$item."\n");

#Call recursive dir to
if(!(@ftp_chdir($conn, $remote_folder)))
die("Cannot change directory to $remote_folder");
}//End for first check of $item: if is_dir($item)
else {
$fp = @fopen($dir."/".$item, "r");
$pwd = @ftp_pwd($conn);
//echo $pwd."\n";
if(@ftp_fput($conn, $item, $fp, $mode)){
//print $dir."\\".$item."\n";
}//End for if uploaded file
}//End for else

}//End for recursive function

#Called to recursive function
#Close the connect to FTP Data

How to fix the problem ?
Thanks to all and sorry for my bad English