I agree about the foreach loop.

In addition, the actual error message (apparently) refers to the variable $IP as being undefined; this is because the assignment to $IP is using a different hash than the one that is being looped through. The loop starts with:

foreach $key(%Servers){

which loops through all of the key/value pairs of the hash %Servers in pseudo-random order (probably not what you wanted, as runrig has said). However, your assignment to $IP uses the variable $key to retrieve values from another hash called %Server, which is undoubtably empty, in fact making $IP undefined.

Also, as has been noted elsewhere, you most certainly do not need the double quotes around scalar values, for example, $Server{$key}: they force unnecessary interpolation, since $Server{$key} itself is already a string.

There is no particular reason to use a hash at all, preferring an array, which will preserve your ordering of IP addresses. I would go one step further and remove the unnecessary call to chomp (since the addresses do not end in newlines):

my @Servers = qw( 128.37.37.201 128.38.38.201 128.39.39.201 ); foreach my $IP ( @Servers ) { my $FTP = Net::FTP->new($IP); if ( $FTP->login($user,$pass) ) { $FTP->ascii(); $FTP->put($File); $FTP->quit; } else { print "Error logging in to $IP: ". $FTP->message ."\n"; } }

dmm


You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime

In reply to Re(dmmiller2k): Net::FTP troubles by dmmiller2k
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.