ftp_raw()函数是PHP中的内置函数,用于向远程服务器(即FTP服务器)发送原始命令。
用法:
ftp_raw( $ftp_connection, $command )
参数:该函数接受上述和以下描述的两个参数:
$ftp_connection:它是必填参数。它指定已经存在的FTP连接。
$command:它是必填参数。它指定要在FTP服务器上执行的命令。
返回值:它以字符串数组形式返回服务器的响应。返回原始数据,不执行任何解析。它对确定是否执行命令没有帮助。
注意:
此功能可用于PHP 4.0.0和更高版本。
以下示例无法在在线IDE上运行。因此,请尝试使用适当的ftp服务器名称在某些PHP托管服务器或localhost中运行。
例:
// Connect to FTP server
// Use a correct 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) {
// Storing response from ftp_raw() in $response
$response = ftp_raw($ftp_connection, "USER abc");
// Printing $response with print_r()
print_r($response);
// Closeing connection
if(ftp_close($ftp_connection)) {
echo "
Connection closed Successfully!";
}
}
?>
输出:
Array ( [0] => 331 Password required for abc )
Connection closed Successfully!