PHP ftp_exec() 函数
示例
在 FTP 服务器上执行命令的请求
<?php
// 连接并登录到 FTP 服务器
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("无法连接到 $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$command = "ls-al > somefile.txt";
// 执行命令
if (ftp_exec($ftp_conn,$command))
{
echo "$command 已成功执行。";
}
else
{
echo "$command 执行失败。";
}
// 关闭连接
ftp_close($ftp_conn);
?>
定义和用法
ftp_exec() 函数用于请求在 FTP 服务器上执行命令。
语法
ftp_exec(ftp_conn, command);
参数值
参数 | 描述 |
---|---|
ftp_conn | 必需。指定要使用的 FTP 连接 |
command | 必需。指定要执行的命令 |
技术详情
返回值 | 如果命令成功执行,则返回 TRUE;否则返回 FALSE。 |
---|---|
PHP 版本 | 4.0.3+ |
❮ PHP FTP 参考