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

I'm trying to log in with Net::FTP, but new() fails. However, if I reload in my browser, it runs the script again and it works fine. To see what would happen, I looped the new() 5 times in a for with a sleep(5) between each connection attempt. The current code is as follows:
my $ftp; for ($i=0;$i<5;$i++) { undef $ftp; if ($ftp = Net::FTP->new("ftp.$dom", Debug => 0)) { last; } if ($i >= 4) { die("The given FTP server could not be found."); } else { sleep 5; } }
It always dies. Even more oddly, I copy and pasted the FTP routines from earlier in the script, and those work without problems.

Replies are listed 'Best First'.
Re: Net::FTP Won't Log In, But Does the Second Time
by guha (Priest) on Aug 03, 2004 at 08:29 UTC

    How about setting Debug to a non-zero value and see whats printed to the terminal?

Re: Net::FTP Won't Log In, But Does the Second Time
by nimdokk (Vicar) on Aug 03, 2004 at 09:34 UTC
    It sounds like you are running this as a CGI or something. Have you tried running this from the commandline? With Debug turned on (Debug => 1), that might help in troubleshooting.
Re: Net::FTP Won't Log In, But Does the Second Time
by danielcid (Scribe) on Aug 03, 2004 at 12:24 UTC
    If you are running it "as a CGI", make sure that your web server is not inside a chroot jail or has not any syscall filtering, like systrace...
    I have this problem some months ago (with Net::Telnet) and then I found out that "systrace" was causing the problem.
    Did it work running from the command line ?

    -DBC
      On this account I don't have SSH access, though I might get it enabled tomorrow . . . I think that this is just one account on the server that the person I'm doing this for has.

      Until then, is there anything else that I can do? I could run it from my own computer in shell, but if the problem really is a utility in the server then that really wouldn't help me much.

      Can I call message() if Debug mode is on? Would I just do that with this?
      $ftp = ...
      print $ftp->message();

Re: Net::FTP Won't Log In, But Does the Second Time
by rjahrman (Scribe) on Aug 04, 2004 at 03:16 UTC
    Never mind!

    Turns out that the issue had absolutely nothing to do with Net::FTP, but that $dom didn't contain what I thought it did. :)