Subject: | SFTP->Get(), SFTP->Put() does not return a status |
Net::SFTP 2.06
Perl version 5.0.6
Unix
After opening an sftp connect, put() does not return a status (success or failure) upon execution as happens with $ftp->put().
While more elegant solutions may exist, it was necessary to use the following snippet to catch file transfer errors:
# $sftp->put() does not have a return value on success/failure.
# NOTHING GETS STORED IN $@ or $!
# no warnings eliminates "Use of uninitialized value in string ne at
# sftp-file-send.plx line ..." error
no warnings;
#wrapping eval in if compared to 0 else die
if (eval{$sftp->put( $file, $target_file, \&callback );} ne 0 ) {
writeLog( "* * * ABNORMAL COMPLETION * * * Unable to SFTP $filename to $target_dir on remote machine $host (check log $log_file for additional information)" );
use warnings;
# $@ SHOULD HOLD ERRORS CAUGHT AS PART OF EVAL ABOVE BUT DOES NOT
unlike
eval {
$sftp = Net::SFTP->new( $host, "user" => $user, "password" => $password, debug => $debug );
};
if ( $@ ) { #handle error opening connection
chomp( $@ );
writeLog( "* * * ABNORMAL COMPLETION * * * Error: $@ trying to connect to remote Machine $host" );
# # # # #
A similar issue occurs with $sftp->get();
I will submit this issue under separate cover.
Thank You,
Mike Shelton
mikedshelton@hotmail.com