Home: Perl Programming Help: Beginner:
access an external file from script



jam
stranger

Apr 2, 2001, 5:47 AM


Views: 1038
access an external file from script

does anyone know how i can access an external file

eg. www.somedomain.com/somefile.txt

from my script which is on another server?

open (FILE,"www.etc"); doesn't seem to work but
i am sure i've seen some other command which
does the job, can't remenber where though!

thanks

jamie



ebennawy
Deleted

Apr 2, 2001, 6:57 AM


Views: 1033
Re: access an external file from script

hope this helps,
maybe you could set up an FTP session to retrieve a copy of the file, and then open the copy into a filehandle as usual...
like this...
NOTE: oops! forgot all about the part where you change working directory. Sorry. Here it is, newly edited...
...
#!/usr/bin/perl -w

use Net::FTP;

my $path = "where/the/file/is";
my $file = "filename";
my $user = "username";
my $pass = "password";

$ftp = Net::FTP->new("www.somedomain.com");
$ftp->login($user, $pass);
$ftp->cwd($path);
$ftp->get($file);

...

Good luck.
Bennawy, E.

Failure is not an option. It is a privelege reserved for those who try.

(This post was edited by ebennawy on Apr 2, 2001, 6:30 AM)


widexl
Novice

Apr 2, 2001, 8:15 AM


Views: 1025
Re: access an external file from script

Try this

use LWP::Simple;
$get_url = "http://www.widexl.com";

$context = get($get_url);

print "Content-type: text/html\n\n";
print "$context\n";






jam
stranger

Apr 3, 2001, 5:00 AM


Views: 1015
Re: access an external file from script

cheers that worked a treat!



sleuth
Enthusiast

Apr 3, 2001, 11:31 PM


Views: 1000
Re: access an external file from script

 
Not to be a nits, but just to let you know, if you get the file using LWP then try to loop through the array, you'll never get passed the first line. Instead you'd have to write the data to a file, open the file then loop.

I started using sockets, if you get the file with a socket it feels like the file is local.

Just to let you know mates,

Tony