yacoubean has asked for the wisdom of the Perl Monks concerning the following question:
I have a simple little script I've been working on that will post the private and public IPs for my machine to my website.
Everything in my script is working fine except for the 'put' command. It just hangs until I get a timeout, at which point my connection quits and the script ends. I am wondering if there is an error in my script, or if it is just my webserver. Or is there a better way to do this? My web host is 1and1, and my site is on a Linux server. TIA.
Here's the last bit of output to my shell:
Net::FTP=GLOB(0x82bce74)>>> STOR /private/myips Net::FTP=GLOB(0x82bce74): Timeout at myip.pl line 43 put failed at myip.pl line 43.
And, here's my code:
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use Net::FTP; $| = 1; print "Getting local ip...\n"; my $local_ip = qx/ifconfig eth0|grep -m 1 inet|awk {\'print \$2\'}|cut + -d \':\' -f2/; chomp($local_ip); print "Got local ip: $local_ip\n"; print "Getting remote ip...\n"; my $remote_ip; my $url = "http://www.whatismyip.com/"; my $ua=new LWP::UserAgent; my $request = new HTTP::Request('GET',$url); # create the http requ +est my $response=$ua->request($request); # perform the http request my $whatisipsite = $response->as_string(); # store the response a +s a string if ($whatisipsite =~ /(Your ip is )+(.*?)( WhatIsMyIP.com)/) { # pars +e out the IP address $remote_ip = $2; } chomp($remote_ip); print "Got remote ip: $remote_ip\n"; my $newipfound = 0; open (my $infile, "myips") or die "Can't open file $!"; while (<$infile>) { if (/$local_ip|$remote_ip/) { } else { $newipfound = 1; } } close $infile; if ($newipfound) { print "New ip found! Sending file to web site...\n"; open (my $outfile , ">myips") or die "Can't open file $!"; print $outfile "$local_ip\n$remote_ip\n"; close $outfile; my $ftp = Net::FTP->new("www.techfeed.net", Debug => 1); $ftp->login("*****",'*****'); $ftp->cwd("/private"); $ftp->ascii(); $ftp->put("myips","/private/myips") or die "put failed ", $ftp->me +ssage; $ftp->quit; print "File sent!\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FTP timeout
by shenme (Priest) on Dec 22, 2004 at 05:00 UTC | |
by yacoubean (Scribe) on Dec 22, 2004 at 05:15 UTC |