PHP | ftp_chdir() function Last Updated : 28 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The ftp_chdir() function is an inbuilt function in PHP which is used to change the current directory on the FTP server. Syntax: ftp_chdir( $ftp_connection, $directory ) Parameter: This function accepts two parameters as mentioned above and described below: $ftp_connection: It is required parameter. It specifies the already existing FTP connection to use for execution of FTP commands or functions.$directory: It is required parameter. It specifies the path in remote server to which current directory to be changed. Return Value: It returns True on success or False on failure.Note: This function is available for PHP 4.0.0 and newer version.The following examples cannot be run on online IDE. So try to run in some PHP hosting server or localhost with a proper ftp server name, user and password.Make sure you have permission to change directory and access to the directory. Example: php <?php // Connect to FTP server // Use a correct ftp server $ftp_server = "localhost"; // Use correct ftp username $ftp_username="username"; // Use correct ftp password corresponding // to the ftp username $ftp_userpass="password"; // Establishing ftp connection $ftp_connection = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); if($ftp_connection) { echo "successfully connected to the ftp server!"; // Logging in to established connection with // ftp username password $login = ftp_login($ftp_connection, $ftp_username, $ftp_userpass); if($login) { // Checking whether logged in successfully or not echo "<br>logged in successfully!"; // ftp_chdir() changing current directory to "htdocs" // remember, you must have folder that will use inside // current directory of ftp server. // Here htdocs folder exists in ftp server inside // base or root directory if (ftp_chdir($ftp_connection, "htdocs")) { echo "<br>Current directory successfully changed to htdocs."; } else { echo "<br>Error while changing current directory."; } } else { echo "<br>login failed!"; } // Closing connection if(ftp_close($ftp_connection)) { echo "<br>Connection closed Successfully!"; } } ?> Output: successfully connected to the ftp server! logged in successfully! Current directory successfully changed to htdocs. Connection closed Successfully! Reference: https://www.php.net/manual/en/function.ftp-chdir.php Comment More infoAdvertise with us Next Article PHP | ftp_chdir() function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function PHP- FTP Similar Reads PHP chdir() Function PHP chdir() function is used to change the current directory to new directory path. It takes only a single argument as new directory path. Syntaxbool chdir(string $new_directory_path)ParametersThis function accepts one parameter, which is mandatory. Return ValueIt returns a boolean operator as retur 2 min read PHP | ftp_exec() function The ftp_exec() function is an inbuilt function in PHP that is used to execute a command on the FTP server. Syntax:Â ftp_exec( $ftp_connection, $command ) Parameters: This function accepts two parameters as mentioned above and described below:Â Â $ftp_connection: It is required parameter. It specifies 2 min read PHP | dir() Function The dir() function in PHP is an inbuilt function which is used to return an instance of the Directory class. The dir() function is used to read a directory, which includes the following: The given directory is opened. The two properties handle and path of dir() are available. Both handle and path pr 2 min read PHP | chroot( ) Function The chroot() function in PHP is an inbuilt function which is used to change the root directory of the current process to directory. The chroot() function changes the current working directory to "/". The chroot() function is only available to GNU and BSD systems, and only when the user is using the 2 min read PHP | ftp_alloc() function The ftp_alloc() function is an inbuilt function in PHP which is used to allocate space for file to be uploaded in FTP server.Syntax:Â Â ftp_alloc( $ftp_connection, $filesize, $result ); Parameter: This function accepts three parameters as mentioned above and described below:Â Â $ftp_connection: It is 3 min read PHP | ftp_delete() function The ftp_delete() function is an inbuilt function in PHP which is used to delete a file on the FTP server. Syntax:Â ftp_delete( $ftp_connection, $file ) Parameters: This function accepts two parameters as mentioned above and described below:Â Â $ftp_connection: It is required parameter. It specifies t 2 min read PHP | closedir( ) Function The closedir() function in PHP is an inbuilt function which is used to close a directory handle. The directory handle to be closed is sent as a parameter to the closedir() function and the closedir() closes the directory handle. The directory handle must be previously opened by the opendir() functio 2 min read PHP | ftp_connect() function The ftp_connect() function is an inbuilt function in PHP which is used to create a new connection to the specified FTP server or Host. When connection is successful then only other FTP functions can be run against the server. Syntax:Â ftp_connect( $ftp_host, $ftp_port, $timeout ); Parameter: This fu 2 min read PHP | is_dir( ) Function The is_dir() function in PHP used to check whether the specified file is a directory or not. The name of the file is sent as a parameter to the is_dir() function and it returns True if the file is a directory else it returns False. Syntax: is_dir($file) Parameters Used: The is_dir() function in PHP 1 min read PHP | ftp_pwd() function The ftp_pwd() function is an inbuilt function in PHP which returns the current directory name of the specified FTP connection. This function was introduced in PHP 4. Syntax: string ftp_pwd( $ftp_conn ) Parameter: This function accepts single parameter $ftp_conn which is used to specify the used FTP 2 min read Like