Solved

Reading a file on another server

Posted on 2000-03-04
12
197 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.

820 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