Thursday, June 18, 2026
HomeLanguagesPHP | ftp_pwd() function

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 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
// PHP program to connect and login
// to the FTP server
 
// Initialize ftp server address
$ftp_server = "ftp.example.com";
 
$ftp_conn = ftp_connect($ftp_server) or
    die("Could not connect to $ftp_server");
 
// Initialize ftp username
$ftp_username = "johndoe";
 
// Initialize ftp password
$ftp_userpass="john#96";
 
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
 
// Change the current directory to php
ftp_chdir($ftp_conn, "php");
 
// Print current directory name (/php)
echo ftp_pwd($ftp_conn);
 
// Close connection
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
// PHP program to connect and login
// to the FTP server
 
// Initialize ftp server address
$ftp_server = "ftp.example.com";
 
// Set the basic connection
$conn_id = ftp_connect($ftp_server);
 
// Initialize ftp username
$ftp_user_name="johndoe";
 
// Initialize ftp password
$ftp_user_pass="john#96";
 
// Login with username and password
$login_result = ftp_login($conn_id,
            $ftp_user_name, $ftp_user_pass);
 
// Change directory to public_html
ftp_chdir($conn_id, 'public_html');
 
// Print current directory /public_html
echo ftp_pwd($conn_id);
 
// Close the connection
ftp_close($conn_id);
 
?>


Output: 

/public_html

Reference: http://php.net/manual/en/function.ftp-pwd.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS