Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/
Share on other sites

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...)

 

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/#findComment-1004197
Share on other sites

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....

 

 

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/#findComment-1004213
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/#findComment-1004740
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/#findComment-1004751
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/190346-ftp-help/#findComment-1004913
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.