Example 1 — Set a Longer Timeout
Raise the timeout before a big transfer so the connection does not give up too soon.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');
if (ftp_set_option($ftp, FTP_TIMEOUT_SEC, 300)) {
echo "Timeout is now ", ftp_get_option($ftp, FTP_TIMEOUT_SEC), " seconds", PHP_EOL;
}
ftp_close($ftp); How It Works
- FTP_TIMEOUT_SEC is the constant for the network timeout setting.
- ftp_set_option() changes the timeout to 300 seconds.
- ftp_get_option() reads the value back to confirm it.
- A longer timeout helps with slow servers and large files.

