Jump to content

[SOLVED] Retrieve list of files from remote ftp server


monkeypaw201

Recommended Posts

Once, again another dilema poped up  :-[ (last one i promise :P )  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..

<?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.

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

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...

<?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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.