[PHP] Problem with recursion and FTP transfer

2004-11-26 Thread [EMAIL PROTECTED]
Hi all
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


Re: [PHP] Problem with recursion and FTP transfer

2004-11-26 Thread Raditha Dissanayake
[EMAIL PROTECTED] wrote:
Hi all
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
Though i don't generally bother with long code samples i decided to make 
an excemption:
i believe calling @ftp_chdir($conn, $remote_folder) in your recursive 
function is wrong instead you should do a CDUP (call the corresponding 
function for that).

btw: get rid of the @ symbols and configure your php.ini so that all 
errors are written to the log file, you will then find it a lot easier 
to debug.

--
Raditha Dissanayake.
--
http://www.radinks.com/print/card-designer/ | Card Designer Applet
http://www.radinks.com/upload/  | Drag and Drop Upload 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php