Sasquire has asked for the wisdom of the Perl Monks concerning the following question:

I have been able to read my own directories within my site using readdir but was wondering if I can use the same CGI script on my site to read a foreign site's directories? My program searches for an image to display (in which case it uses HTML to display this image). So basically I want to use one site to hold the images while another to hold my cgi programs. The CGI script will then look at the foreign site's image directory, and if it finds a certain image, then displays it on my webpage. Is this possible?
  • Comment on How do you read a directory on a foreign site?

Replies are listed 'Best First'.
Re: How do you read a directory on a foreign site?
by ChemBoy (Priest) on May 15, 2001 at 08:16 UTC

    The short answer is no.

    The helpful answer is that readdir gets its information from the local filesystem, which you don't have access to unless you're running programs on that machine (this is generally construed to be a good thing). What your scripts can see of the filesystem of a remote machine depends entirely on what kind of access you have: are you relying entirely on a webserver? If so, you're limited to what the server wants to tell you about the remote directory structure, and you have to take it in the format that the server offers it to you (in which case, LWP and possibly HTML::Parser are worth a look).

    Why do you want to serve up images off a remote server? There might be a better way to accomplish what you're looking to do, if you provide a few details...



    If God had meant us to fly, he would *never* have give us the railroads.
        --Michael Flanders

Re: How do you read a directory on a foreign site?
by asiufy (Monk) on May 15, 2001 at 08:51 UTC
    It depends. Do you have control over this remote site? If yes, there are a number of ways that you can get this done.

    The easiest seems to be to enable directory browsing in your web browser, and parse its output. FTP would also be easy.
    Or, if you want to make it fancy, you can use SOAP and run a subroutine in the image server that'll return the contents of the folder you want, on that remote server.
Re: How do you read a directory on a foreign site?
by Beatnik (Parson) on May 15, 2001 at 15:26 UTC
    Check this discussion on remote directory reading

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.