PHP ftp_exec() 函數
定義和用法
ftp_exec() 函數請求在 FTP 服務器上執行一個程序或命令。
若成功(服務器發送響應代碼 200),則返回 true,否則返回 false。
語法
ftp_exec(ftp_connection,command)
參數 | 描述 |
---|---|
ftp_connection | 必需。規定要使用的 FTP 連接(FTP 連接的標識符)。 |
command | 必需。規定發送到服務器的命名請求。 |
說明
該函數發送一個 SITE EXEC command 請求到 FTP 服務器。
提示和注釋
與 ftp_raw() 函數 不同,ftp_exec() 只有在登錄到 FTP 服務器后才能發送命令。
實例
<?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); ?>