Jump to content

ftp_nlist file or directory


ATM

Recommended Posts

Hey,I need to make a script that uses the php ftp functions to work out whether the items in my array from ftp_nlist are files or directories.I have tried

	if (ftp_size($connection, $file) == -1)	{	echo '' . $file . '<br /> <br />';	}

but I don't think the server supports ftp_size as it gives all of the sized of files as the error; -1.So if you could help me out I would greatly appreciate it.Thank you.

Link to comment
Share on other sites

If the server didn't support ftp_size you would see a PHP error. Since the function gives a return value, it works. I do see a note on the documentation page saying that not all servers support it, but it does not say what happens if the server does not support it. I would assume it causes an error, but it might just give a return value of -1.Assuming the function works, the error with the function either means that the connection does not work, or the file does not exist. If both the connection worked and the file existed, it would give the size. Most likely it can't find the file, so you need to make sure you either change to the working directory first, or give it the full path to the file from the root.You might be able to use ftp_rawlist, it will return an unparsed directory listing. Here is the reference page:http://www.php.net/manual/en/function.ftp-rawlist.phpIn the list of permissions, e.g. "drwxr-x---", the first character will be a d if it is a directory, an l if it is a symbolic link, and a dash if it is a file. There might be other values, you will want to look into Unix permissions to see what the allowed values are.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...