ftp_exec() function in PHP


The ftp_exec() function is used to execute a command on the FTP server.

Syntax

ftp_exec(con, command)

Parameters

  • con − The FTP connection

  • command − The command to execute.

Return

The ftp_exec() function returns TRUE if the command was executed successfully, else FALSE.

Example

The following is an example that executes a command on the FTP server −

<?php
   $ftp_server="192.168.0.4";
   $ftp_user="amit";
   $ftp_pass="tywg61gh";
   $con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
   // list all the files of the remote directory
   $command = 'ls';
   // execute command
   if (ftp_exec($con,$command)) {
      echo "Executed successfully!";
   } else {
      echo "Execution failed!";
   }
   ftp_close($con);
?>

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

141 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements