• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

Problem using function opendir with an ftp url

Hello, I've got a warning using this code, could you tell me what is wrong ??

The code:
///////////////////////////////////////////////////////////////////////////

if ($handleParachiot = opendir('ftp://xxx.xxx.xxx.xxx/ss/Parachiot/'))
{
    echo "Directory handle: $handleParachiot\n";
    echo "Files:\n";

    while (false !== ($file = readdir($handleParachiot))) {
        echo "$file\n";
    }
   
    closedir($handleParachiot);
}
////////////////////////////////////////////////////////////////////////////

Warning: opendir(ftp://xxx.xxx.xxx.xxx/ss/Parachiot/): failed to open dir: not implemented in xxxxxxxxxxxxxxxxxxxxxxxxxxx
0
bruno_boccara
Asked:
bruno_boccara
  • 3
  • 2
1 Solution
 
_GeG_Commented:
hi, this means your php was compiled without ftp support, or the ftp server does not support passive mode
0
 
keteracelCommented:
from the opendir manual at www.php.net:

>As of PHP 5.0.0, support for the ftp://  URL wrapper is included as well.

You need at leat PHP 5.0.0 to use the ftp protocol in an opendir statement.
0
 
keteracelCommented:
This should give you a directory listing (also modified from www.php.net - ftp_nlist):

<?php

// set up basic connection
$conn_id = ftp_connect("ftp://xxx.xxx.xxx.xxx");

// login with username and password
$login_result = ftp_login($conn_id, "anonymous", "anonymous@nowhere.com");

// get contents of the current directory
$contents = ftp_nlist($conn_id, "./ss/Parachiot/");

// output $contents
var_dump($contents);

?>

keteracel
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bruno_boccaraAuthor Commented:
Thank you for your help,
I've got know this error message :

Warning: ftp_connect(): php_network_getaddresses: gethostbyname failed in

Any idea ??
0
 
keteracelCommented:
ok, try taking the ftp:// off the front of the host name... i.e.

$conn_id = ftp_connect("ftp://ftp.mirror.ac.uk");

should be:

$conn_id = ftp_connect("ftp.mirror.ac.uk");
0
 
bruno_boccaraAuthor Commented:
thanks for your help, that was the problem.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now