Example 1 — Connect and Log In
Open a connection, log in with placeholder credentials and report the result.
<?php
$ftp = ftp_connect('ftp.example.com');
if (ftp_login($ftp, 'username', 'password')) {
echo "Logged in successfully", PHP_EOL;
} else {
echo "Login failed", PHP_EOL;
}
ftp_close($ftp); How It Works
- ftp_connect() reaches the server but does not log you in yet.
- ftp_login() sends the username and password to the server.
- The if statement checks the returned boolean.
- ftp_close() ends the connection at the end of the script.

