PHP ftp exec

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : ftp_exec() function

Description

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

Version

(PHP 4 and above)

Syntax

ftp_exec(ftp_connection, command)

Parameters

Name

Description

Required /
Optional

Type

ftp_connection

The link identifier of the FTP connection.

Required

Resource

command

The command to execute.

Required

String

 

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean.

Example :

  1. $ftp_server="192.168.0.2";$ftp_user_name="abc123";$ftp_user_pass="abc123";  

  2. // variable initialization  

  3. $command = 'lcd';  

  4. // set up basic connection  

  5. $conn_id = ftp_connect($ftp_server);  

  6. // login with username and password  

  7. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  

  8. // execute command  

  9. if (ftp_exec($conn_id, $command))   

  10.     echo $command." executed successfully ";  

  11.  else   

  12.     echo "could not execute ". $command;  

  13. // close the connection  

  14. ftp_close($conn_id);  

  15. ?>          

Output :

could not execute lcd