Strange problem with ftp_put. Only a few files get copied.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Strange problem with ftp_put. Only a few files get copied.

Post by amir »

Hi.

I'm developing an auto installer for my CMS system. The installer unpacks a zip file with the files, that i transfered to the server. And to get around permission issues, i unpacked the files into a temp dir, and i'm trying to move everything inside the temp dir, back to root with php's ftp functions. then delete the temp folder.

My problem is that it only transfer a small amount of the files. i have tried the "set_time_limit(0);", but still only a few files get transfered, and i get no errors. I have narrowed it down to the ftp_put command, because making the folders works just fine. On my own server (php 5) , this works fine, but not on a server with php 4. If that makes a difference. Here is the script:

Code: Select all

<?php
set_time_limit(0);
function getmode($file) {
     $ascii = array('.asp$','.bat$','.c$','.cgi$','.cpp$','.css$','.dhtml$','.diz$','.h$','.htm$','.html$','.ini$','.mak$','.nfo$','.pas$','.php$','.php3$','.pl$','.sfv$','.shtm$','.shtml$','.tcl$','.txt$');
     foreach($ascii as $ext) {
          if (eregi($ext, $file)) {
               return FTP_ASCII;
          }
     }
     return FTP_BINARY;
}
function move_recursive($from,$to) {
        global $conn_id;
     $to = str_replace("//","/",$to);
     $current_dir = opendir($from);
     while (false !== ($dir = readdir($current_dir))) {
          if ($dir !== '.' && $dir !== '..') {
               if(is_dir($from .'/'. $dir)) {
                      ftp_mkdir($conn_id, str_replace("//","/",$to ."/". $dir ."/"));
                               if(!move_recursive($from .'/'. $dir,$to .'/'. $dir)) {
                              return false;
                    }
               }
               else {
                    
                    $source = $from ."/". $dir;
                    $dest = str_replace($_SERVER['DOCUMENT_ROOT'],"",$to ."/". $dir);
                    $dest = str_replace("//","/",$dest);
                    if(file_exists(str_replace("//","/",dirname($_SERVER['DOCUMENT_ROOT'].$dest)))) {
                         ftp_put($conn_id, $dest ,$source, getmode($source));
                    }
               }
          }
     }
     closedir($current_dir);
     return true;
}
$ftp_server= "localhost";
$ftp_user = "****";
$ftp_pass = "****";
$conn_id = ftp_connect($ftp_server);
if (!ftp_login($conn_id, $ftp_user, $ftp_pass)) {
        echo 'Connection failed.<br>';
     exit;
}
ftp_pasv ( $conn_id, true );
if(move_recursive(realpath("../temp"),"/")) {
     echo "Finished.";
}
ftp_close($conn_id);
?>
TIA!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

23 regex calls per check is a bit much, especially for ereg. The following performs the same action in a single call.

Code: Select all

preg_match('#\.(?:asp|bat|c|cgi|cpp|css|dhtml|diz|h|html?|ini|mak|nfo|pas|php3?|pl|sfv|shtml?|tcl|txt)$#i', $file);
As for your actual problem, I'm not sure.
Post Reply