SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make ftp_rawlist work recursivley on windows server

    I have written a script which allows me to monitor remote sites for file changes. It works great if the remote server is linux based and returns a recursive list of files from the entire web site.

    However, if the remote server is windows based, I can only get it to return a list from the nominated directory (i.e. ftp_rawlist($conn_id, $root_dir, true), even though recursive is set to 'true'. I have tried various ListOptions, none of which will return a recursive list.

    Am I wasting my time trying to achieve this? Can it be done on a windows server? If so, how?

    Thanks for your time folks
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Sorry, no exp of this but there are some ideas on the online manual page for ftp_rawlist - search the page for "windows".

  3. #3
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks cups - I've already looked at that page - no help, I'm sorry to say.
    If I find a solution I'll post it here. Still need help though.

    cheers
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Oh well, bumps your post up the list all the same ...

  5. #5
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2011
    Location
    Portland
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This was posted on the php.net site.

    PHP Code:

    On my PC (XP and Apache installed) - ftp_rawlist (with Parameter true) does only print a folder list - no subfolders, no files.
    So i created this recursive function that writes all filenames (incl. paths) to a array. I tested it on Mac, Linux and Windows - it works (as long as you don't use folders with spaces...). 
    If you need more information: feel free to set more split[x]-Options and write them to the $files-array. 

    <?php 
    # the directory where ftp_rawlist starts 
    $startdir "example"

    # optional Datatypefilter (leave blank if not needed) 
    $suffix   "gif,png,jpeg,pdf,php"
    # ftp-login 
    $ftp_server ""
    $ftp_user   ""
    $ftp_pw     ""
    $ftp_mode   ""
    $conn_id    ftp_connect($ftp_server); 
    ftp_login($conn_id$ftp_user$ftp_pw) OR die("<br>ftp-login failed"); 
    ftp_pasv($conn_idtrue); 

    #********************************************************************* 
    # create filelist (recursiv) 
    #********************************************************************* 
    $files    = array(); # must be defined here 
    $files    raw_list("$startdir"); 

    #********************************************************************* 
    # print result 
    #********************************************************************* 
    $i 0$count count($files); 
    while (
    $i $count): 
      echo 
    "$files[$i]<br>"
      
    $i++; 
    endwhile; 
    ftp_close($conn_id); 

    #********************************************************************* 
    # rawlist in recursive form (without parameter true!!!) 
    #********************************************************************* 
    function raw_list($folder

    Global 
    $conn_id
    Global 
    $suffix
    Global 
    $files
    $suffixes explode(","$suffix); 
    $list     ftp_rawlist($conn_id$folder); 
    $anzlist  count($list); 
    $i 0
    while (
    $i $anzlist): 
      
    $split    preg_split("/[\s]+/"$list[$i], 9PREG_SPLIT_NO_EMPTY); 
      
    $ItemName $split[8]; 
      
    $endung   strtolower(substr(strrchr($ItemName,"."),1)); 
      
    $path     "$folder/$ItemName"
      if (
    substr($list[$i],0,1) === "d" AND substr($ItemName,0,1) != "."): 
    #      array_push($files, $path); # write directory in array if desired 
         
    raw_list($path); 
      elseif (
    substr($ItemName,0,2) != "._" AND in_array($endung,$suffixes)): 
         
    array_push($files$path); 
      endif; 
      
    $i++; 
    endwhile; 
    return 
    $files

    ?> 

    Ueli, Zurich
    coming soon sitejuju.com my new development portfolio

  7. #7
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks jgetner - I've already tried that. I could only get it to produce a blank page. The search continues
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  8. #8
    SitePoint Zealot
    Join Date
    Jan 2011
    Location
    Portland
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does ftp_rawlist return anything at all or just that single directory?.
    coming soon sitejuju.com my new development portfolio

  9. #9
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It returns details of all the files in the nominated directory, but folders are not listed nor their contents. It's a bit of a mythtery.
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  10. #10
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jgetner View Post
    This was posted on the php.net site.

    PHP Code:

    On my PC (XP and Apache installed) - ftp_rawlist (with Parameter true) does only print a folder list - no subfolders, no files.
    So i created this recursive function that writes all filenames (incl. paths) to a array. I tested it on Mac, Linux and Windows - it works (as long as you don't use folders with spaces...). 
    If you need more information: feel free to set more split[x]-Options and write them to the $files-array. 

    <?php 
    # the directory where ftp_rawlist starts 
    $startdir "example"

    # optional Datatypefilter (leave blank if not needed) 
    $suffix   "gif,png,jpeg,pdf,php"
    # ftp-login 
    $ftp_server ""
    $ftp_user   ""
    $ftp_pw     ""
    $ftp_mode   ""
    $conn_id    ftp_connect($ftp_server); 
    ftp_login($conn_id$ftp_user$ftp_pw) OR die("<br>ftp-login failed"); 
    ftp_pasv($conn_idtrue); 

    #********************************************************************* 
    # create filelist (recursiv) 
    #********************************************************************* 
    $files    = array(); # must be defined here 
    $files    raw_list("$startdir"); 

    #********************************************************************* 
    # print result 
    #********************************************************************* 
    $i 0$count count($files); 
    while (
    $i $count): 
      echo 
    "$files[$i]<br>"
      
    $i++; 
    endwhile; 
    ftp_close($conn_id); 

    #********************************************************************* 
    # rawlist in recursive form (without parameter true!!!) 
    #********************************************************************* 
    function raw_list($folder

    Global 
    $conn_id
    Global 
    $suffix
    Global 
    $files
    $suffixes explode(","$suffix); 
    $list     ftp_rawlist($conn_id$folder); 
    $anzlist  count($list); 
    $i 0
    while (
    $i $anzlist): 
      
    $split    preg_split("/[\s]+/"$list[$i], 9PREG_SPLIT_NO_EMPTY); 
      
    $ItemName $split[8]; 
      
    $endung   strtolower(substr(strrchr($ItemName,"."),1)); 
      
    $path     "$folder/$ItemName"
      if (
    substr($list[$i],0,1) === "d" AND substr($ItemName,0,1) != "."): 
    #      array_push($files, $path); # write directory in array if desired 
         
    raw_list($path); 
      elseif (
    substr($ItemName,0,2) != "._" AND in_array($endung,$suffixes)): 
         
    array_push($files$path); 
      endif; 
      
    $i++; 
    endwhile; 
    return 
    $files

    ?> 

    Ueli, Zurich
    jgetner - thanks for making me take a 2nd look at the code at php.net. With some manipulation, I was able to get it to return an array which contains all the info I need, i.e. a recursive file list, with all file details. Amended code below - I've commented out the original code that I didn't need (works on linux too):

    PHP Code:
    <?php 
    # the directory where ftp_rawlist starts 
    $startdir "wwwroot"

    # optional Datatypefilter (leave blank if not needed) 
    //$suffix   = ""; 
    # ftp-login 
    $ftp_server "ftp.domain.com"
    $ftp_user   "username"
    $ftp_pw     "password"
    $ftp_mode   "pasv"
    $conn_id    ftp_connect($ftp_server); 
    ftp_login($conn_id$ftp_user$ftp_pw) OR die("<br>ftp-login failed"); 
    ftp_pasv($conn_idtrue); 

    #********************************************************************* 
    # create filelist (recursiv) 
    #********************************************************************* 
    $files    = array(); # must be defined here 
    $files    raw_list("$startdir");
    echo 
    '<pre>';
    print_r($files);
    echo 
    '</pre>';
    #********************************************************************* 
    # print result 
    #********************************************************************* 
    /*
     $i = 0; $count = count($files); 
    while ($i < $count): 
      echo "$files[$i]<br>"; 
      $i++; 
    endwhile;
    */ 
    ftp_close($conn_id); 

    #********************************************************************* 
    # rawlist in recursive form (without parameter true!!!) 
    #********************************************************************* 
    function raw_list($folder

    Global 
    $conn_id
    //Global $suffix; 
    Global $files
    //$suffixes = explode(",", $suffix); 
    $list     ftp_rawlist($conn_id$folder);

    $anzlist  count($list); 
    $i 0
    while (
    $i $anzlist): 
      
    $split    preg_split("/[\s]+/"$list[$i], 9PREG_SPLIT_NO_EMPTY);
      
    array_push($split$folder);

      
    $ItemName $split[8]; 
      
    //$endung   = strtolower(substr(strrchr($ItemName,"."),1)); 
      
    $path     "$folder/$ItemName";  
      if (
    substr($list[$i],0,1) === "d" AND substr($ItemName,0,1) != "."):
          
    array_push($files$split);
         
    //array_push($files, $path); # write directory in array if desired
         
    raw_list($path); 
      elseif (
    substr($ItemName,0,2) != "._" /*AND in_array($endung,$suffixes)*/): 
          
    array_push($files$split);
         
    //array_push($files, $path);
      
    endif;
      
    $i++; 
    endwhile;


    return 
    $files

    ?>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •