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

If e.g. I have a get command and it returns 0, I know an error's happened.

I can then check $ftp->code and $ftp->message to find out what went wrong, however this won't work if the server closed the connection and threw me off without giving me a reply.

So how do I detect for an EOF?

Cheers.

  • Comment on NET::FTP - Unexpected EOF on command channel

Replies are listed 'Best First'.
Re: NET::FTP - Unexpected EOF on command channel
by Eureka_sg (Monk) on May 15, 2001 at 18:59 UTC

    Try with Net::FTP debugging on ! It might give you a better idea of what's going on:

    $ftp = Net::FTP->new($host, Debug => 1);

      I have, that's how I worked out it was an unexpected EOF!

      I don't have the log file available to post as I've gone and deleted it before running another version of the program which as yet hasn't gone wrong, however the bit of code reads like this...

      It gets the file and returns 0 if okay, otherwise the it returns code from the server. It doesn't delete yet to move files from the FTP server, it just copies at the moment, and it doesn't cope with EOFs...

      $exempt is 421 if I want it to try again later with a timeout...

      sub ftp_move() { my $exempt=-1; my $code; $exempt=$_[0] if $_[0]; &write_log("+ [$filename] interesting name, moving to incoming + directory.",0); if($ftp->get($filename,$rvf_incoming.$filename)) { $files_moved++; return 0; } $code=$ftp->code; if($code>=400) { &write_log("| [$filename] error getting from FTP site +- ".$code." $@",0) if $code!=$exempt; $files_error++ if $code!=$exempt; return $code; } return 0; }
(tye)Re: NET::FTP - Unexpected EOF on command channel
by tye (Sage) on May 15, 2001 at 21:02 UTC

    You may have to wrap eval { } around the calls to Net::FTP. My information is only 2nd-hand but I've heard that Net::FTP is horrid at error reporting and will die suddenly if it feels like it.

            - tye (but my friends call me "Tye")

      Not to discredit its author(s), but yes, I feel the same way about Net::FTP. It's a really neat tool to do trivial FTP, but when it comes to codes which must handle errors in some elaborate fashion, then you don't get much.

      For anything like that, you just have to write your own version. You may even want to copy Net::FTP and Net::Cmd and hack its internals.

      .... and yes, I have done the above to get more useful data. It's not exactly pleasant :-)

      Once again, though, it's a neat tool. Just not what you want to use for this

        Oh... arse. Thanks for your help.

        It runs every half-hour so if it fails the first time it should pick up the rest later, not perfect though...

Re: NET::FTP - Unexpected EOF on command channel
by jeroenes (Priest) on May 15, 2001 at 19:08 UTC
    Normally spoken, you can use eof. And I would suspect any IO class to have an eof method. Apparently, Net::FTP misses that. You'd better contact the author, if nobody comes up with a better idea.

    Jeroen
    "We are not alone"(FZ)

      That's annoying, I've got 3 days, not 3 weeks...

      Here is the logfile, if anybody can suggest any work arounds...

      Net::FTP=GLOB(0x27d064)>>> PORT 165,47,63,26,178,111 Net::FTP=GLOB(0x27d064)<<< 200 PORT command successful. Net::FTP=GLOB(0x27d064)>>> RETR 01450504.E Net::FTP=GLOB(0x27d064)<<< 150 Opening ASCII mode data connection for +01450504.E (64 bytes). Net::FTP=GLOB(0x27d064)<<< 226 Transfer completed. Net::FTP=GLOB(0x27d064)>>> PORT 165,47,63,26,178,112 Net::FTP=GLOB(0x27d064)<<< 200 PORT command successful. Net::FTP=GLOB(0x27d064)>>> RETR 01450504.P Net::FTP=GLOB(0x27d064)<<< 150 Opening ASCII mode data connection for +01450504.P (1014 bytes). Net::FTP=GLOB(0x27d064)<<< 226 Transfer completed. Net::FTP=GLOB(0x27d064)>>> PORT 165,47,63,26,178,113 Net::FTP=GLOB(0x27d064)<<< 200 PORT command successful. Net::FTP=GLOB(0x27d064)>>> RETR 01450505.E Net::FTP=GLOB(0x27d064)<<< 150 Opening ASCII mode data connection for +01450505.E (169 bytes). Net::FTP=GLOB(0x27d064)<<< 226 Transfer completed. Net::FTP=GLOB(0x27d064)>>> PORT 165,47,63,26,178,114 Net::FTP: Unexpected EOF on command channel at test.pl line 102