Example 1 — Rename a File
Rename a file on the server from draft.txt to final.txt.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');
if (ftp_rename($ftp, 'draft.txt', 'final.txt')) {
echo "Renamed to final.txt", PHP_EOL;
} else {
echo "Rename failed", PHP_EOL;
}
ftp_close($ftp); How It Works
- The connection is opened and you log in as usual.
- ftp_rename() sends the old name and the new name to the server.
- The server changes the name and the function returns true.
- The success message is printed and the connection is closed.

