PHP Function Reference

PHP ftp_close() Function



The PHP ftp_close() function closes the given FTP connection. The function returns true on success or false on failure.

Syntax

ftp_close(ftp)

Parameters

ftp Required. Specify the FTP connection to close.

Return Value

Returns true on success or false on failure.

Example:

The example below shows the usage of ftp_close() function.

<?php
//FTP server to use
$ftp_server = "ftp.example.com";
  
//set up a connection or die 
$ftp = ftp_connect($ftp_server)
    or die("Could not connect to $ftp_server");
   
if($ftp) {
  echo "Successfully connected to $ftp_server!\n";
 
  //close the connection
  if(ftp_close($ftp)) {
    echo "Connection closed successfully!\n"; 
  } 
}
?>

The output of the above code will be:

Successfully connected to ftp.example.com!
Connection closed successfully!

❮ PHP FTP Reference