Open In App

PHP | ftp_close() function

Last Updated : 09 Apr, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The ftp_close() function is an inbuilt function in PHP which is used to close the already exists FTP connection to a specified FTP server or Host. Syntax:
ftp_close( $ftp_connection );
Parameter: This function accepts single parameter $ftp_connection which is required. It specifies the FTP connection to close FTP connection. Return Value: It returns True on success or False on failure. Note:
  • This function is available for PHP 4.0.0 and newer version.
  • The following examples cannot be run on online IDE. So try to run in some PHP hosting server or localhost with proper ftp server name.
Below programs illustrate the ftp_close() function in PHP: Example 1: php
<?php

// Connect to FTP server
$ftp_server = "localhost";

// Establishing ftp connection 
$ftp_connection = ftp_connect($ftp_server) 
    or die("Could not connect to $ftp_server");
 
if($ftp_connection) {
    echo "Successfully connected to the ftp server!";
    
    // Closing  connection
    if(ftp_close($ftp_connection)) {
        echo "<br>Connection closed Successfully!";
    }
}
?>
Output:
Successfully connected to the ftp server!
Connection closed Successfully!
Example 2: Connect to ftp server using port 21. php
<?php

// Connect to FTP server
$ftp_server = "localhost";

// Establishing ftp connection 
$ftp_connection = ftp_connect($ftp_server, 21) 
    or die("Could not connect to $ftp_server");
 
if($ftp_connection) {
    echo "Successfully connected to the ftp server!";
    
    // Closing  connection
    if(ftp_close($ftp_connection)) {
        echo "<br>Connection closed Successfully!";
    }
}
?>
Output:
Successfully connected to the ftp server!
Connection closed Successfully!
Reference:https://www.php.net/manual/en/function.ftp-close.php

Next Article

Similar Reads