FTP Functions in PHP
The FTP extension in PHP allows you to connect to and work with file servers that support the File Transfer Protocol (FTP). It puts a number of functions in your disposal that let you open and login, get files, upload files and directories, rename files and directories, delete files and folders, and get information on the files in an FTP server.
One of these useful functions is ftp_rmdir(), which removes an empty directory from an FTP server. The function accepts two required parameters – the ftp_stream (connection identifier returned by the ftp_connect() function) and the directory to remove.
The first parameter can be an absolute or relative path to an empty directory. The second parameter is a string that specifies the context of the ftp_stream, which controls various runtime options like the timeout in seconds for all network related functions and whether GET or PUT requests with resumepos or startpos will seek to that position at the beginning of the file.
If you need to read the details of the files in an FTP server, there are two inbuilt PHP functions that you can use - ftp_nlist and ftp_rawlist. ftp_rawlist is more advanced and provides the details of every file in a directory including the permissions, user, group, size(in bits), last modified date(month, day, hour) and its name.
If you need to recursively delete a folder, then you can use a recursive version of this function called ftp_rmdirRecursive(). It calls ftp_rmdir() recursively and returns TRUE on success and FALSE on failure.