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

I was wondering what the best way was to use Net::FTP to make file transfers in the background (one at a time), from an FTP server. I need to be able to "time out" a transfer after a certain amount of seconds, I don't want to use fork() and waitpid, I think I remember reading somewhere about using eval() and alarm() in combination to manage this. Any ideas? zonem

Replies are listed 'Best First'.
Re: background ftp transfers
by mitd (Curate) on Aug 10, 2001 at 02:48 UTC
    Net::Ftp has its own Timeout value available in the constructor Net::FTP->new('somehost.com', Timeout=>...).

    So I don't see the problem with forking.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

      If I recall; that timeout value only has an effect when connecting to the FTP server; not for transfers.
      Net::FTP will wait for a put or get to either complete or to fail before it returns control back to the script.
Re: background ftp transfers
by larryk (Friar) on Aug 10, 2001 at 16:08 UTC
    # from perldoc perlipc eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; # ftp op here alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die }
    but this won't make it a background task, just interruptable. oh, and if you're on a doze box alarm isn't implemented.
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      wow; i really should look through the documentation more extensively

      thanks! :)