http://qs321.pair.com?node_id=420311

tohann has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: FTP log files fails with a 426 error code
by runrig (Abbot) on Apr 13, 2016 at 18:43 UTC
    This has been happening to me also. It seems to happen sometimes when downloading large files from some servers. I've got Net::FTP wrapped in our own FTP library, get() is wrapped in an eval, and on error, it checks local and remote file sizes, and calls it success if they match, and then reconnects to the server.
Re: FTP log files fails with a 426 error code
by tohann (Sexton) on Jan 10, 2005 at 14:16 UTC
    Well, I have a resolution, kind of.

    We tried moving the log files to a completely different directory structure and the script worked flawlessly. It has to be something in the directory set up, or something system-level. The Perl script is fine. I'll gladly take this as an answer after all the frustration and fruitless searching. :)

    Trent