Example 1 — Download a File
Fetch a text file from the server and save it locally. The host and login are placeholders.
<?php
$ftp = ftp_connect("ftp.example.com");
ftp_login($ftp, "demo_user", "demo_pass");
if (ftp_get($ftp, "local-notes.txt", "notes.txt", FTP_ASCII)) {
echo "Saved to local-notes.txt", PHP_EOL;
} else {
echo "Download failed.", PHP_EOL;
}
ftp_close($ftp); How It Works
- We connect and log in to the server.
- ftp_get() downloads notes. txt and saves it as local-notes.txt.
- FTP_ASCII is used because it is a plain text file.
- A message is printed based on the true or false result.

