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..


In reply to Re: Net::FTP troubles by Fastolfe
in thread Net::FTP troubles by RedDog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.