ftp_exec()

创建于 2024-12-03 / 80
字体: [默认] [大] [更大]

❮ PHP FTP 参考手册

实例

请求在 FTP 服务器上执行命令:

<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$command = "ls-al > somefile.txt";

// execute command
if (ftp_exec($ftp_conn,$command))
  {
  echo "$command executed successfully.";
  }
else
  {
  echo "Execution of $command failed.";
  }

// close connection
ftp_close($ftp_conn);
?>

定义和用法

ftp_exec() 函数请求在 FTP 服务器上执行一个程序或命令。

若成功(服务器发送响应代码 200),则返回 true,否则返回 false。

语法

ftp_exec(ftp_conn, command);

参数值

参数 描述
ftp_conn 必需。规定要使用的 FTP 连接(FTP 连接的标识符)。
command 必需。规定发送到服务器的命名请求。

说明

该函数发送一个 SITE EXEC command 请求到 FTP 服务器。



技术细节

返回值: 如果命令成功执行,则为 TRUE; 否则为 FALSE
PHP 版本: 4.0.3+

❮ PHP FTP 参考手册
0 人点赞过