Solved

Reading a file on another server

Posted on 2000-03-04
12
191 Views
Last Modified: 2013-12-25
I want to read a file on any server and do something with the text it contains. I know there are a similar question available by searching (Q.10256678) but the source code provided there wont work for me. It fails on the line "use LWP::Simple;", giving me no specific error message, just a notification that the server cant execute the file. If anyone knows how this can be fixed or knows another way to do the thing I want to do, please let me know.

I know that this can be done by using sockets, but I dont know exactly how to do it. Could anyone provide some source code on how to open a socket to an URL and putting that URL's data in a variable $data, or at least tell me how to do it?
0
Comment
Question by:dedsi
  • 6
  • 4
  • 2
12 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 2584944
Program uses unit "Simple" (file simple.pm in subdirectory LWP), but cann't find it! To fix this problem you need find this file and place it in corresponding subfolder (or change path).
0
 
LVL 1

Author Comment

by:dedsi
ID: 2585324
I have found the file "Simple.pm" and it was located in the subdirectory LWP, like you said, so I assume that the path is correct.
0
 
LVL 1

Author Comment

by:dedsi
ID: 2589135
Edited text of question.
0
 
LVL 1

Author Comment

by:dedsi
ID: 2589139
Adjusted points to 300
0
 
LVL 6

Expert Comment

by:andreif
ID: 2590528
Can you post me this program (with simple.pm) by email?
<a href=mailto:filonov@i.am>filonov@i.am</a>
0
 

Accepted Solution

by:
bimpf earned 300 total points
ID: 2590887
I hope the code-sample below will solve your problems. - I took it from "Perl Cookbook" and modified just the last few lines. - It works for me.

test the script by saving it to a file (test.pl) and run it by calling "perl test.pl http://www.yourserver.com/files/yourfile.html"


---- script sarts here----

#!/usr/bin/perl -w
# titlebytes - find the title and size of documents
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;
my $raw_url = shift or die "usage: $0 url\n";
my $url = URI::Heuristic::uf_urlstr($raw_url);
$| = 1;                                  # to flush next line
printf "%s =>\n\t", $url;
my $ua = LWP::UserAgent->new();
$ua->agent("Schmozilla/v9.14 Platinum"); # give it time, it'll get there
my $req = HTTP::Request->new(GET => $url);
$req->referer("http://wizard.yellowbrick.oz");
                                         # perplex the log analysers
my $response = $ua->request($req);
if ($response->is_error()) {
     printf " %s\n", $response->status_line;
 } else {
     my $content = $response->content();
     $DATA=$content;
     printf $DATA;
     }
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:dedsi
ID: 2593060
Ok, it works but where do I put the URL I wish to "visit" in the source code? I want this to run from a homepage and I want to decide which URLs I might be able to visit from within my source (or from a Query string).
0
 

Expert Comment

by:bimpf
ID: 2593122
sorry ... that's no big deal:

you just have to watch the line:
my $raw_url = shift or die "usage: $0 url\n";


=> if you want to assign the variable $raw_url an URL within your perl-script that can simply be done by:

my $raw_url = "http://www.yourdomain.com/file.html";

respectively

my $my_address = "http://www.yourdomain.com/file.html";
my $raw_url = $my_address;


.... that should work.


0
 
LVL 1

Author Comment

by:dedsi
ID: 2602378
have you tried it from a web browser? I cant get it to work for me from a browser but I can run it from the command line (perl test.pl ...). I get a "500 Server Error" message.
0
 

Expert Comment

by:bimpf
ID: 2602421
.. your "500 Server Error" has nothing to do with the question you've asked!!! That means that if the program runs in a command line it should work as a cgi-script too. - If it doesn't you have some kind of syntax-error .. usually some misplaced quotation marks or some "special-characters" .. like "@", "%", or things like that .... but that syntax error has nothing to do with the principle of fetching files from remote severs!!

.... e.g:
if you fetch the content of some remote-html file it usually contains some "special-characters" like the above mentioned "@" or quotationmarks itself ... if you want to print that out into in a browser with e.g.
" print $CONTENT_OF_REMOTFILE"
you will of course get errormessages!!!!!!

=> you have to parse the content of the remote file first and replace all non-allowed characters!!!


.... but that has nothing to do with the question you've asked :-)
0
 

Expert Comment

by:bimpf
ID: 2634196
. I just want to say that I find the grade you gave me not correct ... you wanted a solution for your specific problem - I gave you the exact WORKING answer .. so I can't understand why you've graded me with "C"....
0
 
LVL 1

Author Comment

by:dedsi
ID: 2635542
Okay, when I come to think about it, your answer are actually what I asked for. I guess I put the "low" grade because I couldnt get it to work in a web browser and I thought I had specified that in the question, but I never did. Im sorry. So, what grade do you want (think your answer are worth)? Is there any way to change it by now?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now