Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading a file on another server

Posted on 2000-03-04
12
Medium Priority
?
207 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
URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

 
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 600 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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