ftp_exec

(PHP 4 >= 4.0.3, PHP 5)

ftp_exec -- 请求运行一条 FTP 命令

说明

bool ftp_exec ( resource ftp_stream, string command )

发送一个 SITE EXEC command 请求到 FTP 服务器。如果成功(服务器发送响应代码 200)则返回 TRUE,否则返回 FALSE

例子 1. ftp_exec() 例子

<?php
$command
= 'ls -al';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if(
$res = ftp_exec($conn_id, $command)) {
    echo
"$command executed successfully<br />\n";
    echo
nl2br($res);
} else {
    echo
'could not execute ' . $command;
}
?>

参见 ftp_raw()


add a note add a note User Contributed Notes
chris dot pittman at sonopress dot com
15-Sep-2005 09:34
I've been using the php ftp functions pretty extensively at work.  We've recently discovered that some of the ftp servers we connect to, paticularly in Europe, are using extended passive mode.  On a server using extended passive mode the php ftp functions will timeout.  For those of you who encounter this, the solution is to send the command:

ftp_exec (conn_id, 'epsv4 off' );

Do this immediately after ftp_login and you should be fine.
sam at totallydigital dot co dot nz
16-Dec-2003 05:34
A word of caution, execution via FTP isn't very widely supported.  Check that it works on the servers that you intend to connect to before you start coding something that requires this.