PHP Function Ftp_Chmod
php function ftp_chmod is a handy function that allows you to change file permissions on a remote server via ftp. You can use this if you want to edit and change plugin or theme files that are installed on your website or if you need to make sure the correct css and js files are uploaded to the right location on your web host. This enables you to control the file permissions and protect your site from hackers.
You can also use this if you are using an FTP client such as FileZilla and need to CHMOD a file that is already on the server. In this case you’ll need to know the number of permissions to set for that particular file – usually it’s 644 or 755. Then just go to the ftp client and change the numeric value to the correct one.
ftp_chmod() function takes three parameters: ftp_stream, mode, and filename. The ftp_stream is the connection identifier from the ftp_connect() function, the mode is the new file permissions in octal format, and the filename is the name of the remote file. The function returns a boolean on success or FALSE if it fails to change the file permissions.
If you are on a windows server then an instruction like chmod(filename, 1777) may not work because windows does not handle that type of octal mode values correctly. This is why you should always prefix your octal mode values with 0.