PHP | ftp_close() function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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!";
    }
}
?>

chevron_right


Output:

Successfully connected to the ftp server!
Connection closed Successfully!

Example 2: Connect to ftp server using port 21.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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!";
    }
}
?>

chevron_right


Output:

Successfully connected to the ftp server!
Connection closed Successfully!

Reference:https://www.php.net/manual/en/function.ftp-close.php



My Personal Notes arrow_drop_up

I am unrecognized crazy being with random thoughts

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.