Check if the FTP record is a file or folder with PHP

I am working on a script to connect to FTP and then to upload content.

Now my problem is to determine if each item is a folder or file. My first idea was to try to use ftp_chdir, but that would require me to suppress the error with help @, and I don't want to do this (I don't want to suppress the errors, but instead prefer to handle them correctly).

Is there any other way to check if my items are files or folders?

+4
source share
2 answers

The bad thing about trying ftp_chdiris not the need to suppress errors. This is normal if you have a legitimate reason to expect an error. It rather affects directory changes.

If I take this direction, I will try instead ftp_size, since it has no side effects. It must be unsuccessful for directories and succeed for files.


If you connect to one specific server to find out its directory listing format, use ftp_rawlistand analyze its output to determine if the entry is a file or folder.

A typical list on the * nix server is similar:

drwxr-x---   3 vincent  vincent      4096 Jul 12 12:16 public_ftp
drwxr-x---  15 vincent  vincent      4096 Nov  3 21:31 public_html
-rwxrwxrwx   1 vincent  vincent        11 Jul 12 12:16 file.txt

This is a host dwho tells you if the entry is a directory or not.


, (.. , ).


- MLSD FTP, . PHP .

MLSD ftp_rawlist:
https://secure.php.net/manual/en/function.ftp-rawlist.php#101071

+2

- 2018+

ftp_nlist. ( ), . .., , .

0

Source: https://habr.com/ru/post/1584036/


All Articles