w3resource

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:

<?php
$ftp_server="192.168.0.2";$ftp_user_name="abc123";$ftp_user_pass="abc123";
// variable initialization
$command = 'lcd';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// execute command
if (ftp_exec($conn_id, $command)) 
    echo $command." executed successfully\n";
 else 
    echo "could not execute ". $command;
// close the connection
ftp_close($conn_id);
?>        

Output:

could not execute lcd  

See also

PHP Function Reference

Previous: ftp_delete
Next: PHP MySQli affected_rows



Follow us on Facebook and Twitter for latest update.