Hi,
I got a "problem" with the PHP FTP function. When I connect and login to a server, I have created a script that gets the filename, size and last modified time. But that script is relay slow, because first I use ftp_nlist to get the filenames, then I use ftp_size() to get the filesize and to find out if it is a folder or a file - on all the files in a foreach() loop. Then at last I run ftp_mdtm() on all the files to get the last modified time.

I ques that if I use ftp_rawlist() the script will run a lot faster, but I'm not sure what the different values are?
Is it possible to use that function to determine if the file is a file or a folder and get the filesize?

Thanks!

    Right, the details on [man]ftp_rawlist()[/man] is *nix ls -l output. Let's use the the example on php.net to explain.

    string(65) "drwxr-x---   3 vincent  vincent      4096 Jul 12 12:16 public_ftp"
    

    string(65) is just telling you what to expect, allows for faster pattern matching in certain situations but we don't need to worry about that
    drwxr-x--- this is where things start to get important.
    the first character is the entry type.
    d : directory
    f or - : file
    l : link

    the next 9 characters are all to do with permissions.
    The first three are concerning the owner, in this case the owner can read (r), write (w) and execute (x) the entry. The second three are concerning other users in the same group. In this case they can only read and execute. The third part is for all other users, they can neither read, write to nor execute the entry.
    The next number I'm not sure about but I think it's the number of entries within it, so in the case of a file this will be 1.
    Then we have the user and then the group, in this case the same as the user, we can only assume that they've set things up so each user is in their own group which in my opinion is a little dumb, even if all your users are in the same group (users) this would be beter because it allows them to interact which still keeping system users seperate.
    Then we have the file size, in bytes (doesn't really work for directories, they're always listed as 4096 regardless of how much they have instide them :/)
    Then we have the date and time in the format PCRE /(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s([1-3][0-9]|[1-9])\s([1-2][0-9]|[1-9])🙁[1-5][0-9]|[1-9])/
    (I'm just showing off now 😉)
    And finally you have the directory/file name.
    The last one in their example is a symlink
    www -> public_html
    this is saying that the entry is called www but it resolves to public_html

    HTH
    Bubble

      Actually, you wont get string(65)
      That's part of the var_dump() information.

      The problem is that you'll only get the string, and will have to interpret it yourself.

      The way I wrote a list function for my FTP class was to analyse the string generated by ftp_rawlist(), then parse it accordingly.
      Your mileage may vary from server to server, apparently, so my class probably isnt portable.

        Thanks a lot 😃
        That actually made the script usefully! The way it was, it used up to 30 secs (some times to the timeout limit).

        Much appreciated!

          The second value, the number, does not seem to be the number of entries within the folder. Does anyone know what it is?

            It is the number of immediate subdirectories, including the '.' and '..' entries.

              Originally posted by laserlight
              It is the number of immediate subdirectories, including the '.' and '..' entries.

              Oh, cool. I'd never been sure about that one and the ls man page is no help at all.
              Cheers
              Bubble

                Write a Reply...