note 40332 added to function.ftp-nlist

From: Date: Sun, 29 Feb 2004 07:40:06 +0000
Subject: note 40332 added to function.ftp-nlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-65984@lists.php.net to get a copy of this message
A little correction to king_killa at juggalos4life dot com's note, it isn't ftp_res, it's ftp_size. By the way, here is a complete function that will get all the files on a server, then write them to a array. <?php $ftp1 = ftp_connect('ftp.nowhere1230404.foo') or die("Couldn't connect to server"); ftp_login($ftp1,'foo','bar'); ftp_pasv($ftp1, TRUE); //Passive Mode is better for this //Get them file! echo "Collecting Files on Neodecoder<br>"; //Set defaults just in case. PHP complains anyway if we don't. $dir = ""; function filecollect($dir,$filelist) { global $ftp1; //Get our ftp $files = ftp_nlist($ftp1,$dir); //get files in directory foreach ($files as $file) { $isfile = ftp_size($ftp1, $file); if($isfile == "-1") { //Is a file or directory? $filelist = filecollect($dir.'/'.$file,$filelist,$num); //If a folder, do a filecollect on it } else { $filelist[(count($filelist)+1)] = $file; //If not, add it as a file to the file list } } return $filelist; } $filelist = filecollect($dir,$filelist); echo "<pre>"; print_r($filelist); echo "</pre>"; ?> This is really handy if your trying to transfer all the files from a ftp server to another server. Which, is why I made the script in the first place. heh.. ---- Manual Page -- http://www.php.net/manual/en/function.ftp-nlist.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40332 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40332&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40332&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65984) next »