I am experiencing an intermittent problem with a module written to wrap Net::FTP.
The symptoms are that the two machines (between which the ftp connection
is established) perform various suceessful TCP hand-shakes. But when it
comes to 'put' the file, one machine no longer has the TCP ftp data
transfer port connection. The whole process then hangs as one machine
waits for the other to supply it data that the other machine doesn't
think exists.
The problem does not occur regularly. The files are small. The OS vary
(Unix->Linux). All module versions have been checked. And so forth.
Here is a slightly edited version of the module:
package MyWrapper::FTP;
use vars qw( @ISA );
@ISA = qw( MyWrapper );
require Net::FTP;
use strict;
my $FTP_TIMEOUT = 60;
sub create_connection
{
my ($self, $connection_string) = @_;
$connection_string =~ /^(\w+):(\S+)@(\S+)$/;
my ($login,$password,$host) = ($1,$2,$3);
my $ftp;
eval
{
$login && $password && $host
or die "Can't parse connection string '".$self->connection
+_string."'\n";
$ftp = new Net::FTP($host, (Timeout=>$FTP_TIMEOUT) );
die "FTP: failed to connect to $host: $!\n" if not $ftp;
$ftp->login($login, $password)
or die "FTP: Can not login to $login\@$host\n";
$ftp->binary;
};
if ($@)
{
# Do some logging.
}
$self->set('host', $host);
return $ftp;
}
sub send_file
{
my ($self, $file, $outfile) = @_;
my $host = $self->get('host');
my $ftp = $self->ftp;
my $workfile;
$workfile = 'test.tst'; # Various unrelated decisions
# on what $workfile is occur here.
if( $ftp->put($file, $workfile) )# <--- This is where it apparentl
+y hangs.
{
# Log some intermediary success.
if( $ftp->rename($workfile,$outfile) )
{
# Log some success.
}
else
{
die( "FTP: $file -> $host:$outfile - FAILED: $!\n" );
}
}
else
{
die( "FTP: $file -> $host:$outfile - FAILED: $!\n" );
}
}
1;
- Graq