jargen Posted January 30, 2010 Share Posted January 30, 2010 Hi, I have this script <code> <?php //login to ftp change details via database $list = ftp_nlist($resource, \"/public_html/\"); //unwanted files $unwanted=array(); $unwanted[1]=\".\"; $unwanted[2]=\"..\"; $unwanted[3]=\".htaccess\"; $unwanted[4]=\"cgi\"; $unwanted[5]=\"cgi-bin\"; $unwanted[6]=\"error_log\"; //insert files/folders not to backup via database //end //remove unwanted files and directorys-Needs to be ran for every directory $i=0; foreach($list as $array){ foreach($unwanted as $array2){ if($array2==$array){ unset($list[$i]); } } $i++; } //end //gets list of files and directorys in root $i=0; foreach($list as $array3){ $files[$i]=explode(\".\",$array3); $i++; } $i=0; $file=array(); $directory=array(); while($i != count($files)){ if( count($files[$i]) == 2){ $file[$i]=$files[$i][0].\".\".$files[$i][1]; }else{ $directory[$i]=$files[$i][0]; } $i++; } print_r ($file); print_r ($directory); //end ?> </code> which works fine. But im completly stuck on how to make it get the files from all the directorys and all the directorys in them. So in the end i can download them all. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
jskywalker Posted January 30, 2010 Share Posted January 30, 2010 which works fine. But im completly stuck on how to make it get the files from all the directorys and all the directorys in them. So in the end i can download them all. Any ideas? Thanks http://php.net/manual/en/function.ftp-get.php Quote Link to comment Share on other sites More sharing options...
jargen Posted January 30, 2010 Author Share Posted January 30, 2010 I know how to get a file. But my problem is im not sure how to change my code to make it get a list of all the directory's, subdirectorys,sub-subdirectory etc and all the files within them Quote Link to comment Share on other sites More sharing options...
jskywalker Posted January 30, 2010 Share Posted January 30, 2010 after your code, you have 2 arrays 1 with the filenames in "public_html" and 1 with the directories in "public_html" Try to make this "public_html" a parameter so you can use the same script for every member of the directory-array (make sure new entry's in the arrays get ADDed to the array, and do not overwrite existing entry's...) Quote Link to comment Share on other sites More sharing options...
jargen Posted January 30, 2010 Author Share Posted January 30, 2010 yeah. But how do i make it keep adding all the directorys that it finds and checking them? I cant get my head around the theory of it Quote Link to comment Share on other sites More sharing options...
jskywalker Posted January 30, 2010 Share Posted January 30, 2010 Google for some examples.... (i.e. http://lixlpixel.org/recursive_function/php/recursive_directory_scan/) BTW, there is also some bug in your code I have a file without an extension in its name (there is NO dot in the name) on my system, and your code thinks its a directory.... Quote Link to comment Share on other sites More sharing options...
jargen Posted January 30, 2010 Author Share Posted January 30, 2010 that script dosent seem to work. It only works with local directory's not ftp Quote Link to comment Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 ftp_rawlist Since you are using FTP and you want to fetch files in subdirectories look at that function: <?php $conn = ftp_connect("yoursite.com"); ftp_login($conn, "YourUserName", "Your Password") or trigger_error("FTP Login failed"); // ftp_rawlist (ftp connection, path, recrusive $buff = ftp_rawlist($conn, "/path/you/want/", true); echo "<pre>"; print_r($buff); echo "</pre>"; ?> Should be what you are after. You would do a foreach on the $buff array and just do simple checks etc. Hope that is what you are looking for. Quote Link to comment Share on other sites More sharing options...
jskywalker Posted January 31, 2010 Share Posted January 31, 2010 but the "recursive" part of ftp_rawlist is only working when your FTP-server allow it... Quote Link to comment Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 but the "recursive" part of ftp_rawlist is only working when your FTP-server allow it... It has not been mentioned, perhaps his server does allow it or maybe he can set the server to allow it. Either way it is an option and a pretty good way to do it if it works. Definitely worth mentioning and worth him trying, if it does not work, well at least he tried it. Would you rather me not mention it to him and have him try it? This is a solution to the problem, as such I decided to enlighten him to it. Quote Link to comment Share on other sites More sharing options...
jskywalker Posted February 1, 2010 Share Posted February 1, 2010 but the "recursive" part of ftp_rawlist is only working when your FTP-server allow it... It has not been mentioned, perhaps his server does allow it or maybe he can set the server to allow it. Either way it is an option and a pretty good way to do it if it works. Definitely worth mentioning and worth him trying, if it does not work, well at least he tried it. Would you rather me not mention it to him and have him try it? This is a solution to the problem, as such I decided to enlighten him to it. you are right, but i thought it was worth mentioning the 'potential' problem if it does not work... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.