ftp_cdup — Changes the current directory to the
: FTP stream
This function sends a "CDUP" command to the server.
Performs the same function as ftp_chdir($ftpStream,
PHP 3>= 3.0.13, PHP 4 >= 4.0b4
Example 356. Move to child
directory then back to parent
// Define directory to which to change
$subdir = "oneleveldown";
// Turn on $php_errormsg (PHP 4.0RC1 and up)
// Connect to server, or complain to user and die
$ftpStream = @ ftp_connect("my.ftp.server")
or die("Couldn't connect to FTP server.");
// Log in to server, or complain to user and die
$loginResult = @ ftp_login($ftpStream, "username", "password")
or die("Couldn't log in to FTP server: $php_errormsg");
// Change to directory named 'oneleveldown'
@ ftp_chdir($ftpStream, $subdir)
or die("Couldn't change to directory '$subdir': $php_errormsg");
print "Directory before ftp_cdup(): " . @ ftp_pwd($ftpStream) . "<br>\n";
or die("Couldn't change to parent directory: $php_errormsg");
print "Directory after ftp_cdup(): " . @ ftp_pwd($ftpStream) . "<br>\n";
// Close the connection
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.