I have create a script for FTP function.
When i have testing the script with little file and directory it's ok
The script read data in all folder with recursive function and the same path of data
like C:\backup\folder1\file.txt is the same on remolte folder /httpdcos/folder1/file.txt
The problem is that when i testing the script with MB of files
the recursion is much more speed of transfer of a single file and a
file is copied to a path that is not the same of local folder.
How to fix the problem ?
Sorry for my bad language
<?php
#Mode transfer data $mode = FTP_ASCII; #The base path of remote directory $remote_folder = "/httpdocs"; #Include data for the connection to the FTP server include_once("./config.php");
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
recursive_dir($dir."/".$item);
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)){
//$count++;
//print $dir."\\".$item."\n";
}//End for if uploaded file
fclose($fp);
}
}//End for else
closedir($handle); }//End for recursive function
#Called to recursive function recursive_dir($default_dir); #Close the connect to FTP Data ftp_close($conn); ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php