Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ftp_quit() function in PHP
The ftp_quit() function in PHP is an alias to ftp_close(). It closes an FTP connection and cleans up resources associated with the connection.
Syntax
ftp_quit(connection);
Parameters
connection − The FTP connection resource to close.
Return Value
The ftp_quit() function returns TRUE on success or FALSE on failure.
Example
The following example demonstrates connecting to an FTP server, performing some operations, and then properly closing the connection −
<?php
$ftp_server = "ftp.example.com";
$ftp_user = "kevin";
$ftp_pass = "tywg61gh";
// Establish FTP connection
$con = ftp_connect($ftp_server);
$res = ftp_login($con, $ftp_user, $ftp_pass);
if ($res) {
echo "Connected successfully<br>";
// Change to demo directory
ftp_chdir($con, 'demo');
echo "Current directory: " . ftp_pwd($con) . "<br>";
// Move up one directory
if (ftp_cdup($con)) {
echo "Directory changed!<br>";
} else {
echo "Directory change not successful!<br>";
}
echo "Current directory: " . ftp_pwd($con) . "<br>";
// Close the connection
if (ftp_quit($con)) {
echo "Connection closed successfully<br>";
}
} else {
echo "Connection failed<br>";
}
?>
Connected successfully Current directory: /demo Directory changed! Current directory: / Connection closed successfully
Key Points
ftp_quit()andftp_close()are functionally identicalAlways close FTP connections to free up resources
Returns
TRUEif the connection was successfully closed
Conclusion
The ftp_quit() function provides a clean way to close FTP connections. It's essential for proper resource management and should be called after completing FTP operations to ensure connections are properly terminated.
