tags:

views:

16

answers:

1

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.

+1  A: 

See example of ftp_exec in manual. You can generate files list that way, then download it and parse.

ftp_exec($conn_id, 'ls -al >files.txt');

or if you know the name of directory and it is single one:

ftp_exec($conn_id, 'ls -ld '.$DIRECTORY.' >permissions.txt');

If you don't have exec permission try:

ftp_nlist ($conn, "-ld ".$DIRECTORY);
Piotr Pankowski
I would assume that EXEC is not widely supported or enabled, as I can imagine the security nightmare with that command.
Krumelur
as Krumelur mentioned, we have EXEC disabled on our machines . Any other way ?
Gotys
Try ftp_nlist ($conn, "-ld ".$DIRECTORY);
Piotr Pankowski
yup, that worked, thanks!
Gotys