PHP ftp_exec() 函數(shù)
定義和用法
ftp_exec() 函數(shù)請(qǐng)求在 FTP 服務(wù)器上執(zhí)行一個(gè)程序或命令。
若成功(服務(wù)器發(fā)送響應(yīng)代碼 200),則返回 true,否則返回 false。
語法
ftp_exec(ftp_connection,command)
參數(shù) | 描述 |
---|---|
ftp_connection | 必需。規(guī)定要使用的 FTP 連接(FTP 連接的標(biāo)識(shí)符)。 |
command | 必需。規(guī)定發(fā)送到服務(wù)器的命名請(qǐng)求。 |
說明
該函數(shù)發(fā)送一個(gè) SITE EXEC command 請(qǐng)求到 FTP 服務(wù)器。
提示和注釋
與 ftp_raw() 函數(shù) 不同,ftp_exec() 只有在登錄到 FTP 服務(wù)器后才能發(fā)送命令。
例子
<?php
$command = "ls-al > test.txt";
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","ert456");
if (ftp_exec($conn,$command)
)
{
echo "Command executed successfully";
}
else
{
echo "Execution of command failed";
}
ftp_close($conn);
?>