note 101071 added to function.ftp-rawlist
| From: | JohnnyDoe at osu1 dot php dot net | Date: | Wed, 24 Nov 2010 14:18:22 +0000 |
| Subject: | note 101071 added to function.ftp-rawlist | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174322@lists.php.net to get a copy of this message | ||
In case anybody wants to get a detailed listing using the MLSD command over a passive connection,
the following function might be helpful as a starting point for your own implementation:
function ftp_mlsd($ftp, $directory) {
$ok = @ftp_chdir($ftp, $directory);
if (!$ok) {
return false;
}
$ret = ftp_raw($ftp, 'PASV');
if (preg_match(
'/^227.*\(([0-9]+,[0-9]+,[0-9]+,[0-9]+),([0-9]+),([0-9]+)\)$/',
$ret[0], $matches)) {
$controlIP = str_replace(',', '.', $matches[1]);
$controlPort = intval($matches[2])*256+intval($matches[3]);
$socket = fsockopen($controlIP, $controlPort);
ftp_raw($ftp, 'MLSD');
$s = '';
while (!feof($socket)) {
$s .= fread($socket, 4096);
}
fclose($socket);
$files = array();
foreach (explode("\n", $s) as $line) {
if (!$line) {
continue;
}
$file = array();
foreach (explode(';', $line) as $property) {
list($key, $value) = explode('=', $property);
if ($value) {
$file[$key] = $value;
} else {
$filename = trim($key);
}
}
$files[$filename] = $file;
}
return $files;
}
return false;
}
Please note that this function ignores the setting of ftp_pasv(). Making the function to work
universally for both active and passive connections is left as an exercise to the reader ;-)
----
Server IP: 212.124.37.9
Probable Submitter: 217.92.195.249
----
Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php
Edit -- https://master.php.net/note/edit/101071
Del: integrated -- https://master.php.net/note/delete/101071/integrated
Del: useless -- https://master.php.net/note/delete/101071/useless
Del: bad code -- https://master.php.net/note/delete/101071/bad+code
Del: spam -- https://master.php.net/note/delete/101071/spam
Del: non-english -- https://master.php.net/note/delete/101071/non-english
Del: in docs -- https://master.php.net/note/delete/101071/in+docs
Del: other reasons-- https://master.php.net/note/delete/101071
Reject -- https://master.php.net/note/reject/101071
Search -- https://master.php.net/manage/user-notes.php