in reply to Net::FTP only working occasionally.

Turn on debugging and see if it helps you track down the culprit.

my $ftp = Net::FTP->new($site, Timeout => 60, debug => 1, ) or die "Connection failed to $site.\n";

Another suggestion is to use Net::FTP's error messages instead of your own.
$ftp->login($user, $pass) or die $ftp->message();

Good luck!

Replies are listed 'Best First'.
Re: Re: Net::FTP only working occasionally.
by wolfger (Deacon) on Mar 31, 2003 at 23:50 UTC
    I put in "or die $ftp->message();" and got the error "Invalid number of arguments." the next time it died.

    Then I added "debug => 1" and... the script worked. And it worked the next 5 times I tried it. Note that I never changed the number of arguements... It just suddenly went from invalid to valid, automagically.

    I shall meditate upon this.

    This morning I noticed that the script did not work when cron called it in the middle of the night. I ran it again, and here are the two different debug outputs:
    When the script works
    Net::FTP=GLOB(0x8244e84)>>> TYPE binary
    Net::FTP=GLOB(0x8244e84)<<< 500 'TYPE binary'
    Net::FTP=GLOB(0x8244e84)>>> PORT 192,168,0,10
    Net::FTP=GLOB(0x8244e84)<<< 200 PORT command
    Net::FTP=GLOB(0x8244e84)>>> STOR howllog.html
    Net::FTP=GLOB(0x8244e84)<<< 150 Opening ASCII
    tml.
    Net::FTP=GLOB(0x8244e84)<<< 226 Transfer comp
    Net::FTP=GLOB(0x8244e84)>>> QUIT
    Net::FTP=GLOB(0x8244e84)<<< 221 Goodbye.

    When it doesn't work
    Net::FTP=GLOB(0x8244e84)>>> TYPE binary
    Net::FTP=GLOB(0x8244e84)<<< 500 'TYPE binary' not understood.
    Net::FTP=GLOB(0x8244e84)>>> PORT 192,168,0,10,222,129
    Net::FTP=GLOB(0x8244e84)<<< 501 Invalid number of arguments.

    So my questions are two-fold:
    1) Why is "TYPE binary" sometimes not recognized?
    2) How can I get my perl to keep trying until the send is successful?

    Now I have seen a third output:
    Net::FTP=GLOB(0x8244e84)>>> TYPE binary
    Net::FTP=GLOB(0x8244e84)<<< 500 'TYPE binary' not understood.
    Net::FTP=GLOB(0x8244e84)>>> PORT 192,168,0,10,223,46
    Net::FTP=GLOB(0x8244e84)<<< 200 PORT command successful.
    Net::FTP=GLOB(0x8244e84)>>> STOR howllog.html
    Net::FTP=GLOB(0x8244e84)<<< 150 Opening ASCII mode data connection for howllog.html.
    Net::FTP=GLOB(0x8244e84)<<< 226 Transfer complete.
    Net::FTP=GLOB(0x8244e84)>>> QUIT
    Net::FTP=GLOB(0x8244e84)<<< 221 Goodbye.

    So obviously the success of "TYPE binary" has nothing to do with it. It's the PORT command that's killing me. When it failed, it said "invalid number of arguements", and we can clearly see 6 arguements were passed. In this last example there are 6 arguements as well, but the PORT was successful.

    Back to my meditations