Example 1 — Set File Permissions
Change a remote file to 0644 and print the result. The host and login are placeholders.
<?php
$ftp = ftp_connect("ftp.example.com");
ftp_login($ftp, "demo_user", "demo_pass");
$result = ftp_chmod($ftp, 0644, "index.php");
if ($result !== false) {
echo "New permissions: ", decoct($result), PHP_EOL;
} else {
echo "chmod failed.", PHP_EOL;
}
ftp_close($ftp); How It Works
- 0644 is an octal number: owner can read and write, others can only read.
- ftp_chmod() returns the new permissions as an integer.
- decoct() turns that integer back into an octal string for display.
- The result is compared with !== false to detect failure.

