To open files, we use e.g. this:
open (NNN, "path/filename.ext")
The file being opened is, however, on the same server as the script. My question is, how can I open a file on another server? Simply changing "path/filename.ext" into "http://www.server.com/path/filename.ext" does not work. Then, how?
Tnx for help.
But as soon as I add the stroke
use LWP::UserAgent;
into my script, it starts outputting Internal Server Error.
I tried also LWP::Simple, the result was the same.
Any ideas? Tnx.
Can you FTP to this external server? If so, you may want to bypass LWP and take a look at Net::FTP.
use Net::FTP;# Connect to server
$ftp = Net::FTP->new('ftp.example.com');# Log into server
$ftp->login('anonymous','root@example.com');# Change directory on server
$ftp->cwd('/public_html/subdir');# Set ASCII transfer mode
$ftp->ascii;# Fetch remote file, store it locally
$ftp->get('remote_file.html','local_file.html');# Close connection to server
$ftp->quit;# Slurp whole file into one var
{
local (*INPUT, $/);
open (INPUT, 'local_file.html');
$whole_html_file_in_one_variable = <INPUT>;
}# Delete local file if necessary
# or desired; add your own code to
# do as you will; season to taste!
LWP should do the trick for you; I use it a bunch myself, for things I can't FTP. :) You've tried it, but it didn't work out, so howzabout posting the relevant section of your code for debugging? If that's uncomfortable, you can Sticky me.
Or not. :)
--------------------------------------
#!/usr/bin/perl
print "Content-Type: text/html\n\n";
use strict;
use LWP::UserAgent;
--------------------------------------
... and it results in Internal Server Error (Apache/2.0.52 (Unix) PHP/4.3.10 Server).
It seems that my ISP has no installed LWP::UserAgent.
I think I could go around this obstacle by putting the necessary part of the UserAgent module code, directly into my CGI script. The problem is that I am not familiar with such procedure and I don't know which is the necessary part in the module.