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

Hi Monks,
I am stuck here. I uploaded some images to a different server from where I am running this code, I should read this directory where all my images are and make a link out of every images I find inside of that directory.
I just don't know how to use the "open" to get there since it is in a different server. Any help on that?

$dirforimg="my_ip_number/test/images": opendir(DIR,$dirforimg) || die("Cannot open directory $dirforimg: $! $ +@\n"); @contents = sort readdir(DIR); closedir(DIR); # Format as clickable links foreach my $filename (contents) { print " <a href\"$dirforimg/$filename\">$filename</a>"; }

Thanks a lot!

Replies are listed 'Best First'.
Re: Open directory - Different Server
by holli (Abbot) on Feb 22, 2006 at 13:59 UTC
    That depends on how you are connected to that remote server. Possibilities are smb, http, ftp, etc. Once you tell us that, we can possibly tell you how you can access a directory on that server.


    holli, /regexed monk/
      Sorry, I will be connecting using FTP
        I believe there is a Net::Ftp module in CPAN. Really, you should look at using SSH and the module Net::SSH instead. FTP is very insecure.

        Neil Watson
        watson-wilson.ca

        So you can use the Net::FTP module which is part of the libnet bundle. See the Synopsis in the modules docs for a good example.


        holli, /regexed monk/
Re: Open directory - Different Server
by clinton (Priest) on Feb 22, 2006 at 17:19 UTC
    I'm not sure how big you're planning on making this site - it appears to be pretty small, however you are using at least 2 servers. So...

    Consider, when you upload the images, writing the image location/description/size/other metadata to a database.

    That way you don't have to connect to the other server at all. And it means you can upload your images to any server, just as long as you specify which server it is in your database entry.

    It'll also be quicker to read a few rows from a database than to make an SSH or FTP connection and do a directory lookup.

    But this may be more complicated than you're after.