Solved

Reading a file on another server

Posted on 2000-03-04
12
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

752 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