Skip to content
PHP Logo

What is the purpose of the function ftp_chmod() in PHP?

The function ftp_chmod() in PHP is used to change the permissions of a file or directory on an FTP server. This can be useful when you need to update the permissions of a file to allow or restrict access to it. By using ftp_chmod(), you can easily modify the permissions of files or directories remotely on an FTP server.

php
// Connect to FTP server
$ftp_server = 'ftp.example.com';
$ftp_user = 'username';
$ftp_pass = 'password';
$ftp_connection = ftp_connect($ftp_server);
ftp_login($ftp_connection, $ftp_user, $ftp_pass);

// Change permissions of a file to 755
$filename = '/path/to/file.txt';
ftp_chmod($ftp_connection, 0755, $filename);

// Close FTP connection
ftp_close($ftp_connection);