H
huntingseasonson
Doing batches of FTP transfers. Most of the time they work, sometimes
they dont. When they dont, the error messages seem to be the response
from the FTP server acknowledging my previous command, or empty.
Heres the code:
sub ftp_transfer()
{
my $ftp = Net::FTP->new($host) || _error("Can't connect to host $host:
$@");
_netcmd_error($ftp,"Can't login to $host as $username: "
$ftp->message)
unless $ftp->login($username,$password);
if( $ftp->ls($package) ) {
_log("Remote directory $package already exists");
unless($config{overwrite}) { #no need to continue unless
caller wants to overwrite
$ftp->quit;
return;
}
_log("Overwriting remote directory $package");
}
else {
_netcmd_error($ftp,"Can't create remote directory $package: " .
$ftp->message)
unless $ftp->mkdir($package);
}
_netcmd_error($ftp,"Can't change to remote directory $package: "
.. $ftp->message)
unless $ftp->cwd($package);
_netcmd_error($ftp,"Can't transfer file $file: " . $ftp->message)
unless $ftp->put($file);
_netcmd_error($ftp,"Can't switch to binary mode: " .
$ftp->message) unless $ftp->binary;
###############################################################################
#ERROR COMES FROM HERE
_netcmd_error($ftp,"Can't transfer file $video: " . $ftp->message)
unless $ftp->put($video);
################################################################################
$ftp->quit;
return 1;
}
_error() logs the error and sends an email alert, _netcmd_error calls
quit() on the ftp object and then calls _error()
The error I get is either: "Opening BINARY mode data connection for
xyz.mpg"
or empty.
Humm, I guess its probably better to call binary() 1st. But I cant
understand why the 2nd put() call fails with either nothing in
message(), or the response from the server when I called binary(). The
perldocs say that all calls return a true or false to indicate success
or failure, unless otherwise noted. So it is failing, but the message
is faulty. I really dont know.
Thanks
they dont. When they dont, the error messages seem to be the response
from the FTP server acknowledging my previous command, or empty.
Heres the code:
sub ftp_transfer()
{
my $ftp = Net::FTP->new($host) || _error("Can't connect to host $host:
$@");
_netcmd_error($ftp,"Can't login to $host as $username: "
$ftp->message)
unless $ftp->login($username,$password);
if( $ftp->ls($package) ) {
_log("Remote directory $package already exists");
unless($config{overwrite}) { #no need to continue unless
caller wants to overwrite
$ftp->quit;
return;
}
_log("Overwriting remote directory $package");
}
else {
_netcmd_error($ftp,"Can't create remote directory $package: " .
$ftp->message)
unless $ftp->mkdir($package);
}
_netcmd_error($ftp,"Can't change to remote directory $package: "
.. $ftp->message)
unless $ftp->cwd($package);
_netcmd_error($ftp,"Can't transfer file $file: " . $ftp->message)
unless $ftp->put($file);
_netcmd_error($ftp,"Can't switch to binary mode: " .
$ftp->message) unless $ftp->binary;
###############################################################################
#ERROR COMES FROM HERE
_netcmd_error($ftp,"Can't transfer file $video: " . $ftp->message)
unless $ftp->put($video);
################################################################################
$ftp->quit;
return 1;
}
_error() logs the error and sends an email alert, _netcmd_error calls
quit() on the ftp object and then calls _error()
The error I get is either: "Opening BINARY mode data connection for
xyz.mpg"
or empty.
Humm, I guess its probably better to call binary() 1st. But I cant
understand why the 2nd put() call fails with either nothing in
message(), or the response from the server when I called binary(). The
perldocs say that all calls return a true or false to indicate success
or failure, unless otherwise noted. So it is failing, but the message
is faulty. I really dont know.
Thanks