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:
<?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
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- p5.js | value() Function
- D3.js | d3.min() function
- PHP | Ds\Set add() Function
- D3.js | d3.hcl() Function
- p5.js | nfs() Function
- p5.js | nf() Function
- CSS | rgb() Function
- PHP | Ds\Set first() Function
- p5.js | nfc() function
- PHP | Ds\Map first() Function
- PHP Ds\Map sum() Function
- p5.js | nfp() Function
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.


