Skip to content
Related Articles

Related Articles

PHP | ftp_close() function
  • Last Updated : 09 Apr, 2019

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
  
// 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
  
// 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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :