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 connection. Return Value: It returns the current directory name on success or False on failure. NOTE: This function is available on PHP 4.0.0 and newer versions. Example 1:
php
<?php
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect( $ftp_server ) or
die ("Could not connect to $ftp_server ");
$ftp_username = "johndoe";
$ftp_userpass ="john#96";
$login = ftp_login( $ftp_conn , $ftp_username , $ftp_userpass );
ftp_chdir( $ftp_conn , "php");
echo ftp_pwd( $ftp_conn );
ftp_close( $ftp_conn );
?>
|
Output:
/php
Note: This code cannot be run in few of the online IDE as this do not give permission for ftp connection. If it supports then use a working ftp server url, username, password and moreover then it display the directory name. Example 2:
php
<?php
$ftp_server = "ftp.example.com";
$conn_id = ftp_connect( $ftp_server );
$ftp_user_name ="johndoe";
$ftp_user_pass ="john#96";
$login_result = ftp_login( $conn_id ,
$ftp_user_name , $ftp_user_pass );
ftp_chdir( $conn_id , 'public_html' );
echo ftp_pwd( $conn_id );
ftp_close( $conn_id );
?>
|
Output:
/public_html
Reference: http://php.net/manual/en/function.ftp-pwd.php
Last Updated :
02 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...