PHP ftp chdir

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

PHP : ftp_chdir() function

Description

The ftp_chdir() function is used to change the current directory to a specified directory on an FTP server.

Version

(PHP 4 and above)

Syntax

ftp_chdir(ftp_connection, change_directory)

Parameters

Name

Description

Required /
Optional

Type

ftp_connection

The link identifier of the FTP connection.

Required

Resource

change_directory

The target directory.

Required

String

 

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean

Example :

  1. $ftp_server="192.168.0.2";  

  2. $ftp_user_name="abc123";  

  3. $ftp_user_pass="abc123";  

  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. // change the current directory to test  

  9. if (!ftp_chdir($conn_id, 'test'))  

  10. {  

  11. echo "chdir not successful"; // /test  

  12. }  

  13. else  

  14. echo "chidir successful. Directory changed to :".ftp_pwd($conn_id); // /test  

  15. ftp_close($conn_id);  

  16. ?>