sub cleanExit { my( $Sftp, $errstr, $errcode) = @_; print STDERR "ERROR: $errstr\n"; # $Sftp->quit(); exit $errcode; } sub DoTransfer { my ($srcfile, $sourcedir, $Sftpip,$destdir) = @_; my $Sftp = Net::SFTP::Foreign->new( $Sftpip,user => $SFTPUSER,password => $SFTPPASSWD, "more" => '-v' , ); if( !defined( $Sftp)) { cleanExit( $Sftp, "Cannot open FTP session", 2); } if( !$Sftp->put( "$sourcedir/$srcfile", "$destdir/$srcfile")) { #-- cannot put file cleanExit( $Sftp, "Cannot upload $srcfile ", 5); } }