CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



jam
stranger

Apr 2, 2001, 5:47 AM

Post #1 of 5 (537 views)
access an external file from script Can't Post

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

Post #2 of 5 (532 views)
Re: access an external file from script [In reply to] Can't Post

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

Post #3 of 5 (524 views)
Re: access an external file from script [In reply to] Can't Post

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

Post #4 of 5 (514 views)
Re: access an external file from script [In reply to] Can't Post

cheers that worked a treat!



sleuth
Enthusiast

Apr 3, 2001, 11:31 PM

Post #5 of 5 (499 views)
Re: access an external file from script [In reply to] Can't Post

 
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


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives