php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28907 ftp_chdir issues Warning when Failed to change directory. No error required.
Submitted: 2004-06-24 03:24 UTC Modified: 2004-06-25 07:04 UTC
From: mchizewski at yahoo dot com Assigned:
Status: Not a bug Package: FTP related
PHP Version: 5.0.0RC3 OS: Windows 2000 SP 3
Private report: No CVE-ID: None
 [2004-06-24 03:24 UTC] mchizewski at yahoo dot com
Description:
------------
When ftp_chdir cannot change directory, it produces the following PHP warning.

Warning: ftp_chdir()[http://www.php.net/manual/en/function.ftp-chdir]: Failed to change directory. in C:\Documents and Settings\(...)\ftp.php on line 137

If ftp_chdir cannot change the directory, it should do as the documentation says and just return false.

"Returns TRUE on success or FALSE on failure."


Reproduce code:
---------------
// code as part of a ftp class
function change_ftp_directory () {
	if ($this -> ftp_login === false) {
		return false;
	}
	$this -> change_ftp_directory = ftp_chdir ($this -> ftp_resource, $this -> ftp_path);
	if ($this -> change_ftp_directory === false) {
		return false;
	}
	return true;
}

Expected result:
----------------
It returns false if the change directory path is bad. No PHP error reported.

Actual result:
--------------
Warning: ftp_chdir()[http://www.php.net/manual/en/function.ftp-chdir]: Failed to change directory. in C:\Documents and Settings\(...)\ftp.php on line 137

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-24 15:05 UTC] mchizewski at yahoo dot com
Also please note, if this is not how it should be, the PHP Manual needs to be updated. However, I would much rather see the warning message removed. Unless of course there is a ftp function simular to is_file or is_dir. Right now, I see ftp_chdir the best way of finding this out quicky.
 [2004-06-24 17:07 UTC] mchizewski at yahoo dot com
This is also what happens with the ftp_login function. "Returns TRUE on success or FALSE on failure." It should not give a warning message.
 [2004-06-24 18:22 UTC] pollita@php.net
The warning message stays, I've updated the documentation to explicitly state that the warning message will be issued.

is_dir() and is_file *do* work on ftp:// URLs in PHP5.

if (is_dir('ftp://user:pass@host/path/to/file')) { /* The directory exists */ }

The is_dir() method opens a new connection for reach request so if you plan on doing multiple FS ops, then working via the ftp extension (using ftp_chdir() to check) is probably the best way to go.
 [2004-06-25 01:44 UTC] mchizewski at yahoo dot com
If you are going to keep the warning message, please update the documentation for ftp_login as well.

As you said, the is_dir will work if you are NOT using the ftp functions. My understanding is that the ftp functions are required if you need to login to an ftp server. There is no way to remove the warning message?  It really seems wrong to have an error when it gives you feedback true/false.

Is there any way to get an ftp is_dir function?

I do see putting @ in front of the function does suppress the error message.

Thank you for your help!
 [2004-06-25 07:04 UTC] pollita@php.net
The documentation for both functions was updated, the changes take time (often a week or more) to reach the website.

The ftp functions are NOT "required if you want to login to the ftp server", they're just an alternate API.  is_dir() *DOES* work for ftp urls with or without login details.  The is no need for an ftp_is_dir() as it would duplicate the functionality of ftp_chdir().


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC