Getting directory's permissions via FTP

Posted by Gotys on Stack Overflow See other posts from Stack Overflow or by Gotys
Published on 2010-05-13T10:30:54Z Indexed on 2010/05/13 10:34 UTC
Read the original article Hit count: 229

Filed under:
|

I am trying to get permissions of a directory via FTP command "STAT" like this:

$directory_list = ftp_raw($conn_id,'STAT '.$path);

The above command lists entire directory contents , including files and subdirs. I then search the returned data array for the directory i need to check, and retrieve something like:

drwxr-xr-x   3 user  group     77824 May 13 10:15 Targetdir

This will let me parse the drwxr-xr-x string to find out that the chmod of the Targetdir is 0755.

Problem is, when the containing directory has 5000 files. A) It takes a very long time, and B) the ftp_raw function just returns empty array 1 in 10 runs. I don't know if it's timing out or what exactely is the problem.

Is there are a better way to find directory's permissions ? Is there a way to limit number of retrieved fiels in "STAT" command ? I really need just the top 5 , no need for the other 4995 files.

Does anyone know, why would my command NOT run 100% of the time? Why would it break ? I cannot even reproduce my error, it happens randomly.

© Stack Overflow or respective owner

Related posts about php

Related posts about ftp