Example 1 — Send a Command to the Server
Try to run a command on the server and report the result. The host and login are placeholders.
<?php
$ftp = ftp_connect("ftp.example.com");
ftp_login($ftp, "demo_user", "demo_pass");
if (ftp_exec($ftp, "touch ready.txt")) {
echo "Command accepted by the server.", PHP_EOL;
} else {
echo "Command was refused.", PHP_EOL;
}
ftp_close($ftp); How It Works
- We connect and log in.
- ftp_exec() sends SITE EXEC touch ready. txt to the server.
- Most servers disable this feature, so false is the common answer.
- The script prints a message that matches the result.

