ftp_close()函数是PHP中的内置函数,用于关闭与指定FTP服务器或主机的现有FTP连接。
用法:
ftp_close( $ftp_connection );
参数:该函数接受单个参数$ftp_connection。它指定FTP连接以关闭FTP连接。
返回值:成功返回True,失败返回False。
注意:
此功能可用于PHP 4.0.0和更高版本。
以下示例无法在在线IDE上运行。因此,请尝试使用适当的ftp服务器名称在某些PHP托管服务器或localhost中运行。
以下示例程序旨在说明PHP中的ftp_close()函数:
范例1:
// 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 "
Connection closed Successfully!";
}
}
?>
输出:
Successfully connected to the ftp server!
Connection closed Successfully!
范例2:使用端口21连接到ftp服务器。
// 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 "
Connection closed Successfully!";
}
}
?>
输出:
Successfully connected to the ftp server!
Connection closed Successfully!