Click here to get back home

How do I PUSH an HTTP::POST using perl LWP?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How do I PUSH an HTTP::POST using perl LWP? joemacbusiness 07-23-2008
Posted by joemacbusiness on July 23, 2008, 6:26 pm
Please log in for more thread options
Hi All,

I want to use http POST to push several gzipped files
to another apache server. We need to use this since our
customers only allow access to port 80, so no ssh and no ftp.

I am using perl LWP modules for this.
The problem is that it seems like the POST works like a get (pull)
when I really want it to *push* the many *gz files to another
host.

Here is the code I have so far. This POST works like a "get".

========================= snip =========================

use HTTP::Request::Common qw(POST);
use LWP 5.64; # get the most recent stuff.
$ua = LWP::UserAgent->new;

#########################################################
# this builds a list of files that need to be transferred.
# it creates a local file: /tmp/zipped.list
#########################################################
#
my $req = HTTP::Request->new(POST => 'http://somehostname.company.com/
~user/zipped.list');
$req->content_type('text');

open(F,">/tmp/zipped.list") || print "cannot open /tmp/zipped.list";
#binmode F;
print F $ua->request($req)->content;
close(F);

#########################################################
# this loops through the list and (supposedly) copies the
# files **to** the desthost (ie a push).
# But it really pulls the files down from the desthost
# I want it to push the files to desthost.
#########################################################
#

my $infile = "/tmp/zipped.list";
open(FILELIST,"$infile") || print "cannot open $infile $!";
my @filearray = <FILELIST>;
close(FILELIST);

chdir("/tmp/shipping");
my $pwd = `pwd`;
print " ================================ working directory = $pwd \n";
foreach my $fname (@filearray){
chomp($fname);
print "transferring $fname .... \n";

my $req = HTTP::Request->new(POST => "http://desthost.company2.com/
~user/$fname");
$req->content_type('application/gzip');

open(F,">/tmp/shipping/$fname") || print "cannot open /tmp/
shipping/$fname";
binmode F;
print F $ua->request($req)->content;
close(F);
}

========================= end snip ======================

How do I make the code PUSH the gzipped files to desthost?
This assumes that I have permission on desthost for ~user, which I do.

Any help would be appreciated,

Thanks, Joe M.



Posted by Martijn Lievaart on August 2, 2008, 11:00 am
Please log in for more thread options
On Wed, 23 Jul 2008 15:26:05 -0700, joemacbusiness wrote:

> Hi All,
>
> I want to use http POST to push several gzipped files to another apache
> server. We need to use this since our customers only allow access to
> port 80, so no ssh and no ftp.

If the webserver is only used for this, run sshd on port 80. :-)

M4

Similar ThreadsPosted
Curl/Perl http post performanc issue August 2, 2006, 10:43 pm
HTTP POST without LWP December 26, 2006, 6:07 pm
Newbie HTTP::Request->new(POST => URL); question October 31, 2004, 10:30 pm
HTTP::Request::Common Post problem November 5, 2006, 11:22 pm
HTTP::Request::Common and long Text via POST March 13, 2006, 9:55 am
HTTP Proxy via HTTP Layer by Perl? October 19, 2004, 5:56 pm
Need help understanding an Array push April 10, 2007, 11:33 am
push into hashs of arrays August 24, 2007, 2:00 pm
MySql - push a hash into an array October 2, 2006, 1:43 pm
(trivial) unshift and shift vs push and pop March 22, 2008, 4:32 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap