PHP ftp_exec() Function

Definition and Usage

The ftp_exec() function requests the execution of a program or command on the FTP server.

If successful (the server sends a response code of 200), it returns true, otherwise it returns false.

Syntax

ftp_exec(ftp_connection,command)
Parameter Description
ftp_connection Required. Specifies the FTP connection to be used (identifier of the FTP connection).
command Required. Specifies the naming request sent to the server.

Description

This function sends a SITE EXEC command request to the FTP server.

Tips and Comments

With ftp_raw() Function Different, ftp_exec() can only send commands after logging into the FTP server.

Example

<?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);
?>