For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > lwp beginner question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author lwp beginner question
José J. Cintrón

2005-03-22, 3:56 pm

I'm sure it's a stupid question that has been asked before (probably a
few 1000 times), but here it goes any way...

I have a script that downloads a file from an ftp site see bellow

============
use strict;

# --- Customize here ---

my $url = ftp://ftp.server.com/path/";
my $file = "c:\\download\\MyFILE.EXE";
my $code = 0;
my $fname = "";
my $fend = "-x86.exe";
my $dlfile = "";
my $x = 1;

# --- End customization ---

use LWP::Simple;
use Time::localtime;

while (($code != 200) && ($x <= 999))
{
# --- Generate URL ---
$dlfile = $url.sprintf("%4d%02d%02d-%003d%s", localtime->year+1900,
localtime->mon+1, localtime->mday,$x,$fend);

# --- Download files ---
$code = getstore($dlfile, $file);

$x = $x + 1;
}

print "Exit Code: $code";
============

The script works fine as long as I'm not behind a proxy. As soon as I
get the script behind the proxy where it will reside it ends with a 500
Exit code. Anyone can provide me any info on how to get the script
working behind a proxy? BTW I'm using ActivePerl's 5.8.4.810 on a
Windows box. If I need to install additional modules to enable proxy
that's OK, just point me in the correct direction and maybe a snippet of
code to see how to enable the proxy and talk to the server through it.

In case it makes any difference it is a Squid proxy which is being used
to block which destinations the users can connect to.

TIA for any help!!!
--

+------------------------------------------
| José J. Cintrón - <jcintron@mitre.org>
+------------------------------------------


Steven Schubiger

2005-03-22, 3:56 pm

On 22 Mar, "José J. Cintrón" wrote:

> The script works fine as long as I'm not behind a proxy. As soon as I
> get the script behind the proxy where it will reside it ends with a 500
> Exit code. Anyone can provide me any info on how to get the script
> working behind a proxy?


You may consider using LWP::UserAgent instead:

[snip]
The following methods set up when requests should be passed via a proxy server.

$ua->proxy(\@schemes, $proxy_url)
$ua->proxy($scheme, $proxy_url)

Set/retrieve proxy URL for a scheme:

$ua->no_proxy( $domain, ... )

Do not proxy requests to the given domains. Calling no_proxy without any domains clears the list of domains.

$ua->env_proxy

Load proxy settings from *_proxy environment variables.
[/snip]


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com