Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Net::FTP troubles

by Fastolfe (Vicar)
on Nov 09, 2001 at 03:31 UTC ( [id://124236]=note: print w/replies, xml ) Need Help??


in reply to Net::FTP troubles

What is the purpose of $key and the key to your hashes? Remember that pulling out the keys or hashes as they are won't result in sorted output, so you're going to be connecting to each FTP server in a pseudo-random order. It might be more efficient to just stick these IP's into an array and iterate through the array.
use strict; use Net::FTP; my $Local = 'c:\winnt\profiles\jlewis\desktop'; my $File = "cron.file"; my ($user, $pass) = ("username", "password"); my @servers = qw/ 128.37.37.201 128.38.38.201 128.39.39.201 /; chdir($Local) or die "$Local: $!"; foreach (@servers) { my $FTP = new Net::FTP ($_) or die "Can't connect to $_"; $FTP->login($user, $pass) or die "Can't login as $user" $FTP->ascii; $FTP->put($File) or die "Can't put $File" $FTP->quit; }
As another poster mentioned, you were iterating through %Servers as a whole, which means you were trying to make connections to "1", "128.37.37.201", "2", etc. Since the first one wasn't a valid IP/hostname, the creation of your $FTP object failed (which you weren't checking for), which means your call to $FTP->login() couldn't be done since $FTP wasn't defined. Hence all of those messages.

The warning about the uninitialized value came about because you were doing this: $IP="$Server{$key}" Since $key at one point was "128.37.37.201", you were trying stuff the value of that key in the hash into $IP. Since there was no key by that name (it was a value, remember), the result was undefined, hence that warning.

Hope this helps..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found