Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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