makeshift_theory Posted October 13, 2006 Share Posted October 13, 2006 Ok guys, really need your help on this one. I am trying to create a function that will ftp an entire directory structure and all from a source. Below is the code with the user/pass 'x' out.[code]<?function copydirr($fromDir,$toDir,$chmod=0777,$p1,$verbose=false)/* copies everything from directory $fromDir to directory $toDir and sets up files mode $chmod*/{//* Check for some errors$errors=array();$messages=array();$ftp_server = "ftp.startrekrpg.com";$ftp_user_name = "******";$ftp_user_pass = "************";$conn_id = ftp_connect($ftp_server);$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);$site_ftpdirectory = "http://www.startrekrpg.com/";if((!$login_result) || (!$conn_id)) $errors[] = "Could not connect to ftp or login"; else echo "Connection Accepted.";if(!ftp_chdir($conn_id, $site_ftpdirectory . $toDir) && $p1 != 1)echo "Change Failed" . $site_ftpdirectory . $toDir . "<br><br>";elseif(!ftp_chdir($conn_id, $site_ftpdirectory . $toDir))echo "Change Failed on From" . $site_ftpdirectory . $toDir. "<br><br>";//Error Handling//if (!is_writable($toDir)) // $errors[]='target '.$toDir.' is not writable'; // Source Directory is not writable//if (!is_dir($toDir)) // $errors[]='target '.$toDir.' is not a directory'; // Can't find source directoryif (!is_dir($fromDir)) $errors[]='source '.$fromDir.' is not a directory'; // Can't find directory to ftp toif (!empty($errors)) // If errors are present print them out { if ($verbose) foreach($errors as $err) echo '<strong>Error</strong>: '.$err.'<br />'; return false; }//*/$exceptions=array('.','..');//* Processing$handle=opendir($fromDir);while (false!==($item=readdir($handle))) if (!in_array($item,$exceptions)) { //* cleanup for trailing slashes in directories destinations $fromftp=str_replace('//','/',$fromDir.'/'.$item); $toftp=str_replace('//','/',$to.'/'.$item); //*/ //if (is_file($fromftp)) // { // if (@ftp_put($conn_id, $toftp, $fromftp, FTP_ASCII)) // Copies From to To // { //chmod($to,$chmod); // touch($to,filemtime($from)); // to track last modified time // $messages[]='File copied from '.$fromftp.' to '.$toftp; // } //else // $errors[]='cannot copy file from '.$fromftp.' to '.$toftp; // } // If Creates Directory if (is_dir($fromftp)) { if (@ftp_mkdir($conn_id,$toftp)) { //chmod($to,$chmod); $messages[]='Directory created: '.$toDir.$toftp; } else $errors[]='cannot create directory '.$toDir.$toftp; copydirr($fromftp,$toftp,$chmod,$p1=1,$verbose); } }closedir($handle);//*///* Outputif ($verbose) { foreach($errors as $err) echo '<strong>Error</strong>: '.$err.'<br />'; foreach($messages as $msg) echo $msg.'<br />'; }//*/return true;}$from = "cwillard/sites/BioPharm/";$to = "custom";copydirr($from,$to,$chmod=0777,$p1 = 0,true);?>[/code]It will copy all the files to one folder and the folders to the root folder and it copies the right structure for the "website folder." Link to comment https://forums.phpfreaks.com/topic/23880-ftp-question/ Share on other sites More sharing options...
kanikilu Posted October 13, 2006 Share Posted October 13, 2006 You'd probably get a better response here if you actually asked a question or told us what was wrong with the code you posted... Link to comment https://forums.phpfreaks.com/topic/23880-ftp-question/#findComment-108632 Share on other sites More sharing options...
makeshift_theory Posted October 13, 2006 Author Share Posted October 13, 2006 I thought I did but here goes again:It will copy all the files to one folder and the folders to the root folder and it copies the right structure for the "website folder."Basically to reitterate it doesn't copy the folder structure correctly. Link to comment https://forums.phpfreaks.com/topic/23880-ftp-question/#findComment-108665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.