I wrote some code that will open a text file, which contains a list of servers and their ftp addresses. My code goes through the list of servers, ftp's to each, and pulls specific files, etc.

The code works fine until the Net::FTP comes upon an address that is not accessible for some reason. I would like the script to carry on through the loop of each address, but once he hits that first connect timeout, he can't connect to any other addresses, even if I know they are good.

Here is an example of a manual connect to a server that I can connect to manually (addresses and login info changed):

[root@abcdefgjmp09 PegCount]# ftp 10.222.233.244 Connected to 10.252.156.103. 220 wxyz-bts01 FTP server ready. 530 Please login with USER and PASS. 530 Please login with USER and PASS. KERBEROS_V4 rejected as an authentication type Name (10.222.233.244:root): xxx 331 Password required for xxx. Password: 230 User xxx logged in. Remote system type is UNIX. Using binary mode to transfer files. ftp>

But, when run via script, this address is the 5th in the list. The 1st two are good (can connect), and then he runs into to 2 that are unreachable at the moment. So when we get to the fifth one, I would expect the script to still be able to connect, but he can't:

Connected to CA5 Logged in to CA5 Directory changed on CA5. Got file list from CA5 Getting CA5.201202270000.txt... # Disconnected from CA5 Connected to CA2 Logged in to CA2 Directory changed on CA2. Got file list from CA2 Getting CA2.201202270000.txt... # Disconnected from CA2 Can't ftp to 10.222.200.200: Net::FTP: connect: timeout FTP to 10.222.200.200 aborted. Script paused for a few seconds... Can't ftp to 10.222.201.201: Net::FTP: connect: timeout FTP to 10.222.201.201 aborted. Script paused for a few seconds... Can't ftp to 10.222.233.244: <<address reachable manually FTP to 10.252.156.103 aborted.

Here is the first part of my FTP section of my script...

@records = <BTS>; foreach(@records) { my @files=(); my @sorted_seen=(); my $host=(); ($clli,$host) = split /;/, $_, 2; chomp $host; $ftp=Net::FTP->new($host,Timeout=>15) or $newerr=1; if($newerr) { print "\n\nCan't ftp to $host: $@\n"; print " FTP to $host aborted.\n\n"; next; } else { print "\n\nConnected to $clli\n"; <<continue with file transfer, etc>>

If I move this address to say, 3rd in the list, instead of after the two failures, the script connects to him just fine.

Sorry for the short novel...I have even tried using $ftp->quit but it comes back stating basically that you can't quit an ftp session you were never connected to.


In reply to Looping Through FTP Addresses by he204035

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.