Re: Patch: FTP through HTTP-Proxy (Squid)

Gisle Aas (gisle@aas.no)
20 Jun 1999 01:04:56 +0200


Marc Langheinrich <marclang@cs.washington.edu> writes:

> Not sure if this is interesting enough to be included in the main
> distribution, but it sure annoyed me enough to finally patch the LWP
> library to support it.
> 
> My Intranet here only allows Internet access through an HTTP proxy server
> ("Squid"). Although I can freely "surf" the Web this way, none of my
> standard ftp software (like "ftp", "ncftp" etc) works. However, when I
> follow "ftp://" links through my browser, it seems to be no problem
> accessing ftp sites. This is because HTTP proxies like Squid (don't know
> much about any other, sorry) also support FTP requests (i.e. requests of
> the form "GET ftp://ftp.redhat.com/ HTTP/1.0").


There is something I don't understand here.  If you set:

  $ua->proxy("ftp" => "http://squid.my.site.com");

and then perform a 'GET ftp://ftp.redhat.com'-request, don't you
already get what you describe above.  The LWP/Protocol/ftp.pm module
should not be involved at all.

Regards,
Gisle




> I attached a simplistic patch to "LWP/Protocol/ftp.pm" that checks for an
> "http" proxy to be listed for the request (just set your "ftp_proxy"
> environment variable to point to your HTTP proxy), and then simply
> reblesses the LWP::Protocol::ftp object as an "LWP::Protocol::http" one.
> This way LWP handles the request exactly as my Web browser does. This
> allows me to use all of the standard LWP tools (i.e.  GET, lwp-rget,
> lwp-mirror) for FTP requests through my HTTP firewall (well, at least with
> Squid). 
> 
> I know it's a pretty ugly thing (i.e. morphing the request from ftp into
> http), so it might not be appropriate to be in the standard LWP release,
> but it works great for me and I sure don't want to miss it anymore...
> 
> Note: The patch doesn't check for allowed methods, but the proxy will most
> likely complain with an HTTP error in case it doesn't support it (like POST
> for ftp requests). 
> 
> PS: I _know_ that it's possible to use ftp through a firewall -- if it's
> set up to do so, that is. However, my site isn't, so I have to resort to the
> solution below. Your milage may vary.
>  
> -- 
> Marc Langheinrich
> marclang@cs.washington.edu
> 
> 
> $ diff -c LWP/Protocol/ftp.pm.orig LWP/Protocol/ftp.pm
> *** LWP/Protocol/ftp.pm.orig    Tue Jun 15 17:12:11 1999
> --- LWP/Protocol/ftp.pm Tue Jun 15 17:17:46 1999
> ***************
> *** 36,43 ****
> --- 36,49 ----
>       # check proxy
>       if (defined $proxy)
>       {
> +       if ($proxy =~ /^http/i) {
> +       require LWP::Protocol::http;
> +       bless $self, LWP::Protocol::http;
> +       return $self->request($request, $proxy, $arg, $size, $timeout);
> +       } else {
>         return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
>                                    'You can not proxy through the ftp');
> +       }
>       }
>   
>       my $url = $request->url;
> 
>