Example 1 — Close After Your Work Is Done
Open a connection, do a task, and close it. The host and login are placeholders.
<?php
$ftp = ftp_connect("ftp.example.com");
ftp_login($ftp, "demo_user", "demo_pass");
echo "Working in: ", ftp_pwd($ftp), PHP_EOL;
if (ftp_close($ftp)) {
echo "Connection closed.", PHP_EOL;
} How It Works
- We open the connection and log in.
- ftp_pwd() shows the server is ready and we are in the root.
- ftp_close() ends the session and returns true.
- The script prints a short confirmation.

