• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 854
  • 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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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