PHP ftp chmod

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

PHP : ftp_chmod() function

Description

The ftp_chmod() function is used to set permissions on a specified remote file via FTP.

Version

(PHP 5 )

Syntax

ftp_chmod(ftp_connection, imode, filename) 

Parameters

Name

Description

Required /
Optional

Type

ftp_connection

The link identifier of the FTP connection.

Required

Resource

imode

The new permissions, specified as an octal value.

Required

Integer

filename

The remote file name.

Required

String

 

Return value

New file permissions on success or FALSE on error.

Value Type : Integer.

Example :

  1. $ftp_server="192.168.0.2";  

  2. $ftp_user_name="abc123";  

  3. $ftp_user_pass="abc123";  

  4. $file = 'D:/datasoft/test/test.txt';  

  5. // set up basic connection  

  6. $conn_id = ftp_connect($ftp_server);  

  7. // login with username and password  

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

  9. // try to chmod $file to 644  

  10. if (ftp_chmod($conn_id, 0755, $file) !== false) {  

  11.  echo "$file chmoded successfully to 755 ";  

  12. } else {  

  13.  echo "could not chmod $file ";  

  14. }  

  15. // close the connection  

  16. ftp_close($conn_id);  

  17. ?>