Solved

Reading a file on another server

Posted on 2000-03-04
12
189 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
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…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

8 Experts available now in Live!

Get 1:1 Help Now