monkeypaw201 Posted April 22, 2008 Share Posted April 22, 2008 Once, again another dilema poped up (last one i promise ) i need to get a list of files from a remote FTP server.. i tried this: <?php if ($handle = opendir('ftp://server.com/directory')) { echo "Directory handle: $handle\n"; echo "Files:\n"; while (false !== ($file = readdir($handle))) { echo "$file\n"; } closedir($handle); } ?> and it didn't work.. Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 <?php $ftp_conn = ftp_connect("ftp.whatever.com") or die("Could not connect"); ftp_login($ftp_conn,"USER","PASS"); echo "Files:<br />"; $files_in_dir = ftp_nlist($conn,".")); foreach ($files_in_dir as $val) { echo $val . "<br />"; } ftp_close($conn); ?> Fill in your info. Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523619 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 ok, thanks for the speedy reply, but i'm connecting without user/pass... Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523621 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Don't use ftp_login then and try it. Or use an anonymous login. Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523625 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 ok, so i ran the following code: <?php $ftp_conn = ftp_connect("ftp.whatever.com") or die("Could not connect"); echo "Files:<br />"; $files_in_dir = ftp_nlist($conn,".")); foreach ($files_in_dir as $val) { echo $val . "<br />"; } ftp_close($conn); ?> and it spat a blank page at me Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523632 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 ok, so i ran the following code: <?php $ftp_conn = ftp_connect("ftp.whatever.com") or die("Could not connect"); echo "Files:<br />"; $files_in_dir = ftp_nlist($conn,".")); foreach ($files_in_dir as $val) { echo $val . "<br />"; } ftp_close($conn); ?> and it spat a blank page at me Put in the correct FTP server... Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523633 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 ok, no offense, but im not stupid... i did replace it.. Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523638 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 You said "I ran the following code", so I thought you copied it exactly as it was. >_> Sorry, but you'd be surprised on these forums. Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523639 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 no prob, any suggestions? anyone? Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523640 Share on other sites More sharing options...
marcus Posted April 22, 2008 Share Posted April 22, 2008 <?php $conn = ftp_connect("ftp.****.com") or die("Cannot connect to FTP server"); $log = ftp_login($conn, "****", "***"); $raw = ftp_nlist($conn, "/public_html"); ftp_close($conn); echo "<b>Files:</b><br><br>"; foreach($raw AS $file){ if(substr($file, 0, 1) != '.' && strpos($file, '.')){ echo $file . "<br>"; } } ?> i get: Files: AC_RunActiveContent.js Blink 182 - All The Small Things.mp3 call.wav index.php portal content.6_to_6.update.gcf song.swf Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523651 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 brilliant Quote Link to comment https://forums.phpfreaks.com/topic/102265-solved-retrieve-list-of-files-from-remote-ftp-server/#findComment-523660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.