Hello everyone, I'm trying to FTP some log files from server A to server B. This Perl script runs on server B and FTPs to server A and does get()s. It transfers the first file correctly, but then subsequent gets on that connection fail. See the debug messages and STDOUT output below:
Connecting to server(web1) as xxxxxx... Net::FTP: Net::FTP(2.65) Net::FTP: Exporter(5.566) Net::FTP: Net::Cmd(2.21) Net::FTP: IO::Socket::INET(1.26) Net::FTP: IO::Socket(1.27) Net::FTP: IO::Handle(1.21) Net::FTP=GLOB(0x8389760)<<< 220 "Access is being monitored - Unauthori +zed access is prohibited" Connected... Net::FTP=GLOB(0x8389760)>>> user xxxxxx Net::FTP=GLOB(0x8389760)<<< 331 Please specify the password. Net::FTP=GLOB(0x8389760)>>> PASS .... Net::FTP=GLOB(0x8389760)<<< 230 Login successful. Have fun. Logged in... Net::FTP=GLOB(0x8389760)>>> CWD /aaaa/bbbbbbb/ccc/ Net::FTP=GLOB(0x8389760)<<< 250 Directory successfully changed. Reading /aaaa/bbbbbbb/ccc/ Net::FTP=GLOB(0x8389760)>>> PASV Net::FTP=GLOB(0x8389760)<<< 227 Entering Passive Mode (999,999,999,99, +999,26) Net::FTP=GLOB(0x8389760)>>> LIST /aaaa/bbbbbbb/ccc/access_log.0107 Net::FTP=GLOB(0x8389760)<<< 150 Here comes the directory listing. Net::FTP=GLOB(0x8389760)<<< 226 Directory send OK. Net::FTP=GLOB(0x8389760)>>> PASV Net::FTP=GLOB(0x8389760)<<< 227 Entering Passive Mode (999,999,999,99, +999,53) Net::FTP=GLOB(0x8389760)>>> RETR /aaaa/bbbbbbb/ccc/access_log.0107 Net::FTP=GLOB(0x8389760)<<< 150 Opening BINARY mode data connection fo +r /aaaa/bbbbbbb/ccc/access_log.0107 (1073993 bytes). Net::FTP=GLOB(0x8389760)<<< 226 File send OK. getting /aaaa/bbbbbbb/ccc/access_log.0107 to /wwww/xxxxxx/yyyyyy/zz +z/access_log.0107 (1073993 bytes)...done. Net::FTP=GLOB(0x8389760)>>> PASV Net::FTP=GLOB(0x8389760)<<< 227 Entering Passive Mode (999,999,999,99, +999,73) Net::FTP=GLOB(0x8389760)>>> LIST /aaaa/bbbbbbb/ccc/agent_log.0107 Net::FTP=GLOB(0x8389760)<<< 150 Here comes the directory listing. Net::FTP=GLOB(0x8389760)<<< 226 Directory send OK. Net::FTP=GLOB(0x8389760)>>> PASV Net::FTP=GLOB(0x8389760)<<< 227 Entering Passive Mode (999,999,999,99, +999,78) Net::FTP=GLOB(0x8389760)>>> RETR /aaaa/bbbbbbb/ccc/agent_log.0107 Net::FTP=GLOB(0x8389760)<<< 150 Opening BINARY mode data connection fo +r /aaaa/bbbbbbb/ccc/agent_log.0107 (540485 bytes). Net::FTP=GLOB(0x8389760)<<< 426 Failure writing network stream. Unable to close datastream at FTPWebLogs.pl line 62 getting /aaaa/bbbbbbb/ccc/agent_log.0107 to /wwww/xxxxxx/yyyyyy/zzz +/agent_log.0107 (540485 bytes)... ERROR::426:Opening BINARY mode data connection for /aaaa/bbbbbbb/ccc/a +gent_log.0107 (540485 bytes). Failure writing network stream. ... more failures from more log files ...
Each subsequent file will fail until the FTP connection is terminated and then reopened. At that point the first one will successfully transfer and the rest will fail. Here is the relevant code snippet:
foreach my $serverDir (split(',', $serverDirs)) { addMessage("Connecting to server(" . $props{'ftp_server'} . ") as " + . $props{'ftp_username'} . "...\n"); $ftp = Net::FTP->new($props{'ftp_server'}, Debug => $isDebug, Passi +ve => 1) or error("Cannot connect to " . $props{'ftp_server'} . ": $@ +"); addMessage("Connected...\n"); $ftp->login($props{'ftp_username'}, $props{'ftp_password'}) or erro +r($props{'ftp_username'} . " cannot login to " . $props{'ftp_server'} + . ": " . $ftp->message, 1); addMessage("Logged in...\n"); $ftp->cwd("$baseDir$serverDir"); addMessage("Reading $baseDir$serverDir\n"); foreach my $file (split(',', $props{'files_to_move'})) { $file .= ".$formattedDate"; my $fileSize = $ftp->size("$baseDir$serverDir$file"); addMessage(" getting $baseDir$serverDir$file to $destDir$serve +rDir$file ($fileSize bytes)..."); if ($fileSize > 0) { $ftp->get("$baseDir$serverDir$file", "$destDir$serverDir$file +") or error($ftp->code . ":" . $ftp->message, 0); addMessage("done.\n"); } else { addMessage("\n Not getting file because it's empty, but +creating an empty file anyway.\n"); `touch $destDir$serverDir$file`; } } $ftp->quit(); undef $ftp; }
Any ideas why the network stream is failing?

Thanks,
Trent

In reply to FTP log files fails with a 426 error code by tohann

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.