| 1 | package EAI::FTP 1.921; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; use feature 'unicode_strings'; use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Exporter qw(import); use Net::SFTP::Foreign (); use Net::SFTP::Foreign::Constants qw( SFTP_ERR_LOCAL_UTIME_FAILED ); use Net::FTP (); use Text::Glob qw(match_glob); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw(confess longmess); use Log::Log4perl qw(get_logger); use File::Temp qw(tempfile); use Data::Dumper qw(Dumper); use Scalar::Util 'blessed'; use Fcntl ':mode'; # for S_ISREG check in removeFilesOlderX | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use EAI::DateUtil qw(get_curdatetime get_curdate addDatePart parseFromYYYYMMDD convertEpochToYYYYMMDD); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # for passwords that contain <#|>% we have to use shell quoting on windows (special "use" to make this optional on non-win environments) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | BEGIN { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=10.5
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | if ($^O =~ /MSWin/) {require Win32::ShellQuote; Win32::ShellQuote->import();} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our @EXPORT = qw(removeFilesOlderX fetchFiles putFile moveTempFile archiveFiles removeFiles login getHandle setHandle); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my %ftpHandles; # ftp handle lookup, all connections created are stored here, $RemoteHost is lookup key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | my $ftp; # active SFTP handle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $RemoteHost = ""; # active RemoteHost string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # wrappers for different FTP implementations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # wrapper for getting error/message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _error () { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=2 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return $ftp->error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | return $ftp->message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # wrapper for getting file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub _get ($$;$$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: not called CC=3 SCAR=24.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my ($remoteFile, $localFile,$queue_size,$additionalParams) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | return $ftp->get($remoteFile, $localFile, queue_size => $queue_size, ($additionalParams ? %$additionalParams : ())); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return $ftp->get($remoteFile, $localFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # wrapper for globbing files | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _glob ($;$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glob: not called CC=7 SCAR=40.3
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my ($remoteFile,$withoutPath) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # separate glob from path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($remotePath,$remoteGlob) = ($remoteFile =~ /^(.*)\/(.*?)$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my @returnedFiles = $ftp->glob($remoteFile, names_only => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($withoutPath and $remoteGlob) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$withoutPath and $remoteGlob
MC/DC0%0/2
$withoutPath and $remoteGlob
$withoutPath
$remoteGlob
Truth table0%0/3
A and B
A= $withoutPathB= $remoteGlob
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return map {substr($_,length($remotePath)+1)} @returnedFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return @returnedFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($remoteGlob eq "") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $remotePath = "."; # no path found in $remoteFile, so current working dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $remoteGlob = $remoteFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my @returnedFiles = match_glob ($remoteGlob, $ftp->ls($remotePath)); # get all files in remote path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return map { (($remotePath eq "." || $withoutPath) ? $_ : $remotePath."/".$_) } @returnedFiles; # filter files by glob | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$remotePath eq "." or $withoutPath
MC/DC0%0/2
$remotePath eq "." or $withoutPath
$remotePath eq "."
$withoutPath
Truth table0%0/3
A or B
A= $remotePath eq "."B= $withoutPath
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # wrapper for globbing files in current working dir older than given time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub _ls_age ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ls_age: not called CC=5 SCAR=34.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my ($mtimeToKeep) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return $ftp->ls('.', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | wanted => sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # callback function is being passed the read files in a reference to hash with 3 keys: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # filename, longname (as from ls -l) and "a", which is a Net::SFTP::Foreign::Attributes object that contains atime, mtime, permissions and size of the file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $attr = $_[1]->{a}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # if "wanted" returns true (mod time is older than mtimeToKeep), then the file is being added to the returned array | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $logger->trace("file: ".$_[1]->{filename}.",mtime: ".$attr->mtime.",mtimeToKeep: ".$mtimeToKeep) if $logger->is_trace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return $attr->mtime < $mtimeToKeep && S_ISREG($attr->perm); # add file if mod time < required mod time AND it is a regular file... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$attr->mtime < $mtimeToKeep && S_ISREG($attr->perm)
MC/DC0%0/2
$attr->mtime < $mtimeToKeep && S_ISREG($attr->perm)
$attr->mtime < $mtimeToKeep
S_ISREG($attr->perm)
Truth table0%0/3
A && B
A= $attr->mtime < $mtimeToKeepB= S_ISREG($attr->perm)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my @returnedFiles = $ftp->ls('.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $matchedFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | for my $file (@returnedFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $logger->trace("file: ".$file.",mtime: ".$ftp->mdtm($file).",mtimeToKeep: ".$mtimeToKeep) if $logger->is_trace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my %file = (filename => $file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | push @$matchedFiles, \%file if $ftp->mdtm($file) < $mtimeToKeep; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return $matchedFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # wrapper for getting time of file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub _mtime ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mtime: not called CC=3 SCAR=24.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($remoteFile) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $attr = $ftp->stat($remoteFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return $attr->mtime if $attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $ftp->mdtm($remoteFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # wrapper for putting file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _put ($$;$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_put: not called CC=3 SCAR=24.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my ($localFile,$doSetStat,$additionalParams) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # always set late_set_perm to 1 and copy_perm and copy_time to $doSetStat, further additionalParams from additionalParams reference | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my %additionalParams = ((late_set_perm => 1, copy_perm => $doSetStat, copy_time => $doSetStat), ($additionalParams ? %$additionalParams : ())); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return $ftp->put($localFile, $localFile, %additionalParams); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $ftp->put($localFile, $localFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # wrapper for removing file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub _remove ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove: not called CC=2 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($remoteFile) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $ftp->remove($remoteFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $ftp->delete($remoteFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # wrapper for setting current working directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub _setcwd ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setcwd: not called CC=2 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my ($remoteDir) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $ftp->setcwd($remoteDir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return $ftp->cwd($remoteDir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # wrapper for getting status | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub _status () { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_status: not called CC=2 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($ftp->isa('Net::SFTP::Foreign')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return $ftp->status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return ""; # no equivalent in Net:FTP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # remove all files in FTP server folders that are older than a given years/months/days | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub removeFilesOlderX ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeFilesOlderX: not called CC=18 SCAR=58.3
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $param = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my @removeFolders = @{$param->{remove}{removeFolders}} if $param->{remove}{removeFolders}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if (defined $ftp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | for my $folder (@removeFolders) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $newDate = addDatePart(addDatePart(addDatePart(get_curdate(),-$param->{remove}{year},"y"),-$param->{remove}{mon},"m"),-$param->{remove}{day},"d"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $logger->info("remove files in FTP (archive)folder older than $param->{remove}{year} years,$param->{remove}{mon} months and $param->{remove}{day} days (decreased in this order), resulting in cut off date $newDate"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $mtimeToKeep = parseFromYYYYMMDD($newDate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $remoteDir = ($param->{remoteDir} ? $param->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$param->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if (_setcwd($remoteDir.$folder)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $logger->debug("changed into $remoteDir$folder"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $files = _ls_age($mtimeToKeep) or $logger->error("can't get file list, reason: "._error().", status: "._status().longmess()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | for my $file (@$files) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $logger->info("$remoteDir$folder:".($param->{simulate} ? "simulate removal of: " : "removing: ").$file->{filename}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | unless ($param->{simulate}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | _remove($file->{filename}) or $logger->error("can't remove $file->{filename}: "._error().", status: "._status().longmess()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $logger->info("$remoteDir$folder: no Files to remove !") if !@$files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $logger->error("can't change into remote-directory $remoteDir$folder: "._error().", status: "._status().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $logger->info("remove files finished ..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $logger->error("no ftp connection opened!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # fetch files from FTP server | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub fetchFiles ($$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchFiles: not called CC=28 SCAR=65.6
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my ($FTP,$param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # ignore errors for a file that was either removed/archived with the first successful run or is optional | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $suppressGetError = ((($FTP->{fileToRemove} || $FTP->{fileToArchive}) && $param->{firstRunSuccess}) || $param->{fileToRetrieveOptional}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
($FTP->{'fileToRemove'} || $FTP->{'fileToArchive'}) && $param->{'firstRunSuccess'} || $param->{'fileToRetrieveOptional'}
$FTP->{"fileToRemove"} || $FTP->{"fileToArchive"} and $param->{"firstRunSuccess"}
$FTP->{"fileToRemove"} or $FTP->{"fileToArchive"}
MC/DC0%0/4
($FTP->{'fileToRemove'} || $FTP->{'fileToArchive'}) && $param->{'firstRunSuccess'} || $param->{'fileToRetrieveOptional'}
$FTP->{"fileToRemove"}
$FTP->{"fileToArchive"}
$param->{"firstRunSuccess"}
$param->{'fileToRetrieveOptional'}
Truth table0%0/8
A or B and C || D
A= $FTP->{"fileToRemove"}B= $FTP->{"fileToArchive"}C= $param->{"firstRunSuccess"}D= $param->{'fileToRetrieveOptional'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $queue_size = $FTP->{queue_size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $queue_size = 1 if !$queue_size; # queue_size bigger 1 causes often connection issues | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (defined $ftp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$FTP->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if (_setcwd($remoteDir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $logger->debug("changed into $remoteDir"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $remoteFile = ($FTP->{path} ? $FTP->{path}."/" : "").$param->{fileToRetrieve}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $localPath = ($FTP->{localDir} ? $FTP->{localDir} : $param->{homedir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $localPath .= "/" if $localPath !~ /.*[\/\\]$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $localFile = $localPath.$param->{fileToRetrieve}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($remoteFile =~ /\*/) { # if there is a glob character then glob and do multiple get ! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $logger->info("fetching fileglob $remoteFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my @multipleRemoteFiles = _glob($remoteFile); # list retrieved files (including potential path) for fetching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my @multipleFiles = _glob($remoteFile, 1); # list retrieved files (without path) for later processing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $logger->debug("glob $remoteFile returned @multipleFiles"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | @{$param->{retrievedFiles}} = @multipleFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | for (my $i = 0; $i < @multipleFiles; $i++) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $logger->debug("fetching file ".$multipleRemoteFiles[$i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | _get($multipleRemoteFiles[$i], $localPath.$multipleFiles[$i], $queue_size, $FTP->{additionalParamsGet}) or do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | unless (_error() == SFTP_ERR_LOCAL_UTIME_FAILED) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($suppressGetError) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | no warnings 'uninitialized'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $logger->debug("can't get remote-file ".$multipleRemoteFiles[$i].", reason: "._error().", error message suppressed because of \$param{firstRunSuccess}(".$param->{firstRunSuccess}.") or \$param{fileToRetrieveOptional}(".$param->{fileToRetrieveOptional}.")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $logger->error("error: can't get remote-file ".$multipleRemoteFiles[$i]." from glob $remoteFile, reason: "._error().", status: "._status().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | @{$param->{retrievedFiles}} = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $logger->info("multiple get with $remoteFile retrieved following files into $localPath: @multipleFiles"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $logger->info("fetching file $remoteFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $mod_time = _mtime($remoteFile); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $FTP->{dateOfFetchedFile} = convertEpochToYYYYMMDD($mod_time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $logger->debug("get file $remoteFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | @{$param->{retrievedFiles}} = ($param->{fileToRetrieve}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | _get($remoteFile, $localFile, $queue_size, $FTP->{additionalParamsGet}) or do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | unless (_error() == SFTP_ERR_LOCAL_UTIME_FAILED) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ($suppressGetError) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | no warnings 'uninitialized'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $logger->debug("can't get remote-file $remoteFile, reason: "._error().", error message suppressed because of \$param{firstRunSuccess}(".$param->{firstRunSuccess}.") or \$param{fileToRetrieveOptional}(".$param->{fileToRetrieveOptional}.")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $logger->error("can't get remote-file $remoteFile, reason: "._error().", status: "._status().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | @{$param->{retrievedFiles}} = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $logger->info("fetched file $remoteFile to $localFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ($mod_time and !$FTP->{dontDoUtime}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mod_time and not $FTP->{"dontDoUtime"}
MC/DC0%0/2
$mod_time and not $FTP->{"dontDoUtime"}
$mod_time
not $FTP->{"dontDoUtime"}
Truth table0%0/3
A and not(B)
A= $mod_timeB= not $FTP->{"dontDoUtime"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | utime($mod_time,$mod_time,$localFile) or $logger->warn("couldn't set time for $localFile: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $logger->error("can't change into remote-directory $remoteDir, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $logger->error("no ftp connection opened!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # puts file to FTP server | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub putFile ($$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
putFile: not called CC=25 SCAR=64.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my ($FTP,$param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my @localFiles = (); my $localFile = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | @localFiles = @{$param->{filesToWrite}} if $param->{filesToWrite} and ref($param->{filesToWrite}) eq "ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$param->{"filesToWrite"} and ref $param->{"filesToWrite"} eq "ARRAY"
MC/DC0%0/2
$param->{"filesToWrite"} and ref $param->{"filesToWrite"} eq "ARRAY"
$param->{"filesToWrite"}
ref $param->{"filesToWrite"} eq "ARRAY"
Truth table0%0/3
A and B
A= $param->{"filesToWrite"}B= ref $param->{"filesToWrite"} eq "ARRAY"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $localFile = $param->{fileToWrite} if $param->{fileToWrite}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if (!$localFile and @localFiles == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $localFile and @localFiles == 0
MC/DC0%0/2
not $localFile and @localFiles == 0
not $localFile
@localFiles == 0
Truth table0%0/3
not(A) and B
A= not $localFileB= @localFiles == 0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $logger->error("no file(s) to upload (fileToWrite or filesToWrite parameter) !".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | push @localFiles, $localFile if $localFile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (defined $ftp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $doSetStat = ($FTP->{dontDoSetStat} ? 0 : 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$FTP->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if (_setcwd($remoteDir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $logger->debug("changed into $remoteDir"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | for $localFile (@localFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($FTP->{dontUseTempFile}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $logger->info("uploading file $localFile \$doSetStat: $doSetStat"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if (!_put($localFile, $doSetStat, $FTP->{additionalParamsPut})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $logger->error("can't upload local file $localFile to remote dir $FTP->{remoteDir}, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # safe method for uploading in case a monitor "listens": upload temp file, then rename remotely to final name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # first rename to temp... locally | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | rename $localFile, "temp.".$localFile or $logger->error("can't rename local file $localFile to temp.$localFile, reason: $!".longmess()) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $logger->info("uploading file temp.$localFile, \$doSetStat: $doSetStat"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (!_put("temp.$localFile", $doSetStat, $FTP->{additionalParamsPut})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $logger->error("error: can't upload local file temp.$localFile to ${remoteDir}/temp.$localFile, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $logger->info("uploaded file temp.$localFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # then name back again remotely | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if (!$FTP->{dontMoveTempImmediately}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $logger->debug("Sftp: remote rename temp file temp.$localFile auf $localFile ..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ($ftp->rename("temp.".$localFile,$localFile)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $logger->debug("Sftp: temporary file $remoteDir/temp.$localFile renamed to $localFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $logger->error("can't rename remote-file $remoteDir/temp.$localFile to $localFile, reason: "._error().longmess()) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # last rename temp locally as well for further processing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | rename "temp.".$localFile, $localFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $logger->error("can't change into remote-directory $remoteDir, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $logger->error("no ftp connection opened!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | $logger->info("finished uploading file(s) @localFiles ".($FTP->{dontUseTempFile} ? "" : "(as temp. files)")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # move temp file on FTP server | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | sub moveTempFile ($$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
moveTempFile: not called CC=12 SCAR=50.5
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my ($FTP, $param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | my $localFile = $param->{fileToWrite} or do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $logger->error("no file to upload (fileToWrite parameter) !".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $logger->info("final rename of temp Files for $localFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if (defined $ftp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$FTP->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$FTP->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $FTP->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if (_setcwd($remoteDir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $logger->debug("changed into $remoteDir"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($ftp->rename("temp.".$localFile,$localFile)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $logger->debug("temporary file ${remoteDir}/temp.$localFile renamed to $localFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $logger->error("error: can't rename remote-file ${remoteDir}/temp.$localFile to $localFile, reason:"._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $logger->error("can't change into remote-directory ${remoteDir}, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $logger->error("no ftp connection opened!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # move remote files being in a remote directory into the archive directory (relative to remote directory only if glob) or delete them | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub archiveFiles ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
archiveFiles: not called CC=31 SCAR=69.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my @filesToArchive = @{$param->{filesToArchive}} if $param->{filesToArchive}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $archiveTimestamp = $param->{timestamp}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | $archiveTimestamp = get_curdatetime()."." if !defined($param->{timestamp}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if (defined $ftp and @filesToArchive) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ftp and @filesToArchive
MC/DC0%0/2
defined $ftp and @filesToArchive
defined $ftp
@filesToArchive
Truth table0%0/3
A and B
A= defined $ftpB= @filesToArchive
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $logger->info("archiving files @filesToArchive"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | my $remoteDir = ($param->{remoteDir} ? $param->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$param->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | my $archiveDir = ((substr($param->{archiveDir},-1) eq "/" || $param->{archiveDir} eq "") ? $param->{archiveDir} : $param->{archiveDir}."/") if $param->{archiveDir}; $archiveDir.=""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
substr($param->{"archiveDir"}, -1) eq "/" or $param->{"archiveDir"} eq ""
MC/DC0%0/2
substr($param->{"archiveDir"}, -1) eq "/" or $param->{"archiveDir"} eq ""
substr($param->{"archiveDir"}, -1) eq "/"
$param->{"archiveDir"} eq ""
Truth table0%0/3
A or B
A= substr($param->{"archiveDir"}, -1) eq "/"B= $param->{"archiveDir"} eq ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if (_setcwd($remoteDir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $logger->debug("changed into $remoteDir"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | for my $remoteFile (@filesToArchive) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | $logger->debug("archiving $remoteFile to ".($archiveDir ? $archiveDir : "same folder")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ($remoteFile =~ /\*/) { # if glob character contained, then move multiple files | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my @remoteFiles = $ftp->glob($remoteFile, names_only => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | for my $specFile (@remoteFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # $specFile is a relative path to current folder (being $remoteDir, the names_only => 1 doesn't help here) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my ($specFilePathOnly, $specFileNameOnly) = ($specFile =~ /^(.*\/)(.*?)$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | $specFileNameOnly = $specFile if $specFileNameOnly eq ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ($ftp->rename($specFile,$specFilePathOnly.$archiveDir.$archiveTimestamp.$specFileNameOnly)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $logger->debug("remote-file $specFile archived to $specFilePathOnly$archiveDir$archiveTimestamp$specFileNameOnly"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $errmsg = _error(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | $logger->error("error: can't rename remote-file $specFile to $specFilePathOnly$archiveDir$archiveTimestamp$specFileNameOnly, reason: $errmsg".longmess()) if $errmsg !~ /No such file or directory/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | $logger->warn("error: $errmsg".longmess()) if $errmsg =~ /No such file or directory/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if ($ftp->rename($remoteFile,$archiveDir.$archiveTimestamp.$remoteFile)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $logger->debug("remote-file $remoteDir/$remoteFile archived to $archiveDir$archiveTimestamp$remoteFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $errmsg = _error(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | $logger->error("error: can't rename remote-file $remoteDir/$remoteFile to $archiveDir$archiveTimestamp$remoteFile, reason: $errmsg".longmess()) if $errmsg !~ /no such file or directory/i and $errmsg !~ /does not exist/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$errmsg =~ /no such file or directory/iu or $errmsg =~ /does not exist/iu
MC/DC0%0/2
$errmsg =~ /no such file or directory/iu or $errmsg =~ /does not exist/iu
$errmsg =~ /no such file or directory/iu
$errmsg =~ /does not exist/iu
Truth table0%0/3
A or B
A= $errmsg =~ /no such file or directory/iuB= $errmsg =~ /does not exist/iu
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | $logger->warn("error: $errmsg".longmess()) if $errmsg =~ /no such file or directory/i or $errmsg !~ /does not exist/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$errmsg =~ /no such file or directory/iu or not $errmsg =~ /does not exist/iu
MC/DC0%0/2
$errmsg =~ /no such file or directory/iu or not $errmsg =~ /does not exist/iu
$errmsg =~ /no such file or directory/iu
not $errmsg =~ /does not exist/iu
Truth table0%0/3
A or not(B)
A= $errmsg =~ /no such file or directory/iuB= not $errmsg =~ /does not exist/iu
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $logger->error("can't change into remote-directory ${remoteDir}, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $logger->error("no ftp connection opened".longmess()) unless $ftp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | $logger->error("no files to archive given".longmess()) unless @filesToArchive; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # delete remote files | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | sub removeFiles ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeFiles: not called CC=20 SCAR=60.4
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my ($param) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | my @filesToRemove = @{$param->{filesToRemove}} if $param->{filesToRemove}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if (defined $ftp and @filesToRemove) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ftp and @filesToRemove
MC/DC0%0/2
defined $ftp and @filesToRemove
defined $ftp
@filesToRemove
Truth table0%0/3
A and B
A= defined $ftpB= @filesToRemove
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $logger->info("removing files @filesToRemove"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | my $remoteDir = ($param->{remoteDir} ? $param->{remoteDir} : ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | _setcwd(undef) or $logger->error("can't change into home (\$param->{noDirectRemoteDirChange} is set, first changing to home)".longmess()); # starting / means start from home... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
MC/DC0%0/2
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
substr($remoteDir, 0, 1) eq "/"
$param->{"noDirectRemoteDirChange"}
Truth table0%0/3
A and B
A= substr($remoteDir, 0, 1) eq "/"B= $param->{"noDirectRemoteDirChange"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if (_setcwd($remoteDir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $logger->debug("changed into $remoteDir"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | for my $remoteFile (@filesToRemove) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if (_remove($remoteFile)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $logger->debug("removed remote-file $remoteFile"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $errmsg = _error(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $logger->error("error: can't remove remote-file $remoteFile, reason: $errmsg".longmess()) if $errmsg !~ /no such file/i and $errmsg !~ /does not exist/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$errmsg =~ /no such file/iu or $errmsg =~ /does not exist/iu
MC/DC0%0/2
$errmsg =~ /no such file/iu or $errmsg =~ /does not exist/iu
$errmsg =~ /no such file/iu
$errmsg =~ /does not exist/iu
Truth table0%0/3
A or B
A= $errmsg =~ /no such file/iuB= $errmsg =~ /does not exist/iu
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | $logger->warn("error: can't remove remote-file $remoteFile, reason: $errmsg".longmess()) if $errmsg =~ /no such file/i or $errmsg !~ /does not exist/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$errmsg =~ /no such file/iu or not $errmsg =~ /does not exist/iu
MC/DC0%0/2
$errmsg =~ /no such file/iu or not $errmsg =~ /does not exist/iu
$errmsg =~ /no such file/iu
not $errmsg =~ /does not exist/iu
Truth table0%0/3
A or not(B)
A= $errmsg =~ /no such file/iuB= not $errmsg =~ /does not exist/iu
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $logger->error("can't change into remote-directory $remoteDir, reason: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | $logger->error("no ftp connection opened".longmess()) unless $ftp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | $logger->error("no files to remove given".longmess()) unless @filesToRemove; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # login, creating a new ftp connection | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | sub login ($$;$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=49 SCAR=77.6
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my ($FTP,$setRemoteHost,$enforceConn) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | (!$setRemoteHost) and do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $logger->error("remote host not set in \$setRemoteHost".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $RemoteHost = $setRemoteHost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | if (!defined($ftpHandles{$RemoteHost}) or (defined($enforceConn) and $enforceConn)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $ftpHandles{$RemoteHost} or defined $enforceConn and $enforceConn
defined $enforceConn and $enforceConn
MC/DC0%0/3
not defined $ftpHandles{$RemoteHost} or defined $enforceConn and $enforceConn
not defined $ftpHandles{$RemoteHost}
defined $enforceConn
$enforceConn
Truth table0%0/4
not(A) or B and C
A= not defined $ftpHandles{$RemoteHost}B= defined $enforceConnC= $enforceConn
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $logger->debug((defined($enforceConn) && $enforceConn ? "enforceConn is defined" : "ftp connection doesn't exist").", creating new ftp connection"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $enforceConn and $enforceConn
MC/DC0%0/2
defined $enforceConn and $enforceConn
defined $enforceConn
$enforceConn
Truth table0%0/3
A and B
A= defined $enforceConnB= $enforceConn
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | undef $ftpHandles{$RemoteHost} if defined($ftpHandles{$RemoteHost}); # close ftp connection if open. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $logger->info("ftp connection already exists, using handle from \$ftpHandles{'$RemoteHost'}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $ftp = $ftpHandles{$RemoteHost}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # checking if existing connection still usable (ftp host may have terminated it) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (_setcwd(undef)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $logger->warn("reconnecting because existing connection had a problem: "._error().longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | undef $ftpHandles{$RemoteHost}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $maxConnectionTries = $FTP->{maxConnectionTries}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # for unstable connections, retry connecting max $maxConnectionTries. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $connectionTries = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # quote passwords containing chars that can't be passed via windows shell to ssh_cmd (\"....\>...\") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $pwd = $FTP->{pwd}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ($^O =~ /MSWin/ and !$FTP->{dontUseQuoteSystemForPwd}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$^O =~ /MSWin/u and not $FTP->{"dontUseQuoteSystemForPwd"}
MC/DC0%0/2
$^O =~ /MSWin/u and not $FTP->{"dontUseQuoteSystemForPwd"}
$^O =~ /MSWin/u
not $FTP->{"dontUseQuoteSystemForPwd"}
Truth table0%0/3
A and not(B)
A= $^O =~ /MSWin/uB= not $FTP->{"dontUseQuoteSystemForPwd"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | $pwd = Win32::ShellQuote::quote_system($pwd) if ($pwd and $pwd =~ /[()"<>&]/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pwd and $pwd =~ /[()"<>&]/u
MC/DC0%0/2
$pwd and $pwd =~ /[()"<>&]/u
$pwd
$pwd =~ /[()"<>&]/u
Truth table0%0/3
A and B
A= $pwdB= $pwd =~ /[()"<>&]/u
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $debugLevel = $FTP->{FTPdebugLevel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | if (defined($FTP->{hostkey}) || defined($FTP->{privKey}) || $FTP->{SFTP}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $FTP->{"hostkey"} or defined $FTP->{"privKey"} or $FTP->{"SFTP"}
defined $FTP->{"hostkey"} or defined $FTP->{"privKey"}
MC/DC0%0/3
defined $FTP->{"hostkey"} or defined $FTP->{"privKey"} or $FTP->{"SFTP"}
defined $FTP->{"hostkey"}
defined $FTP->{"privKey"}
$FTP->{"SFTP"}
Truth table0%0/4
A or B or C
A= defined $FTP->{"hostkey"}B= defined $FTP->{"privKey"}C= $FTP->{"SFTP"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if (!$FTP->{sshInstallationPath}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $logger->error("no \$FTP->{sshInstallationPath} defined!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if (!defined($FTP->{pwd}) and !$FTP->{privKey}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $FTP->{"pwd"} or $FTP->{"privKey"}
MC/DC0%0/2
defined $FTP->{"pwd"} or $FTP->{"privKey"}
defined $FTP->{"pwd"}
$FTP->{"privKey"}
Truth table0%0/3
A or B
A= defined $FTP->{"pwd"}B= $FTP->{"privKey"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | $logger->error("neither \$FTP->{pwd} nor \$FTP->{privKey} defined!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ($FTP->{additionalParamsNew} and ref($FTP->{additionalParamsNew}) ne "HASH") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$FTP->{"additionalParamsNew"} and ref $FTP->{"additionalParamsNew"} ne "HASH"
MC/DC0%0/2
$FTP->{"additionalParamsNew"} and ref $FTP->{"additionalParamsNew"} ne "HASH"
$FTP->{"additionalParamsNew"}
ref $FTP->{"additionalParamsNew"} ne "HASH"
Truth table0%0/3
A and B
A= $FTP->{"additionalParamsNew"}B= ref $FTP->{"additionalParamsNew"} ne "HASH"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $logger->error("\$FTP->{additionalParamsNew} is not ref to hash".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($FTP->{additionalMoreArgs} and ref($FTP->{additionalMoreArgs}) ne "ARRAY") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$FTP->{"additionalMoreArgs"} and ref $FTP->{"additionalMoreArgs"} ne "ARRAY"
MC/DC0%0/2
$FTP->{"additionalMoreArgs"} and ref $FTP->{"additionalMoreArgs"} ne "ARRAY"
$FTP->{"additionalMoreArgs"}
ref $FTP->{"additionalMoreArgs"} ne "ARRAY"
Truth table0%0/3
A and B
A= $FTP->{"additionalMoreArgs"}B= ref $FTP->{"additionalMoreArgs"} ne "ARRAY"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $logger->error("\$FTP->{additionalMoreArgs} is not ref to array".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $logger->info("connecting to $RemoteHost using SSH FTP"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my @moreparams; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | push @moreparams, "-v" if $debugLevel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | push @moreparams, ("-hostkey", $FTP->{hostkey}) if $FTP->{hostkey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | push @moreparams, ("-hostkey", $FTP->{hostkey2}) if $FTP->{hostkey2}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | push @moreparams, ("-i", $FTP->{privKey}) if $FTP->{privKey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | push @moreparams, @{$FTP->{additionalMoreArgs}} if $FTP->{additionalMoreArgs}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ftp->error or $connectionTries == $maxConnectionTries
MC/DC0%0/2
not $ftp->error or $connectionTries == $maxConnectionTries
not $ftp->error
$connectionTries == $maxConnectionTries
Truth table0%0/3
not(A) or B
A= not $ftp->errorB= $connectionTries == $maxConnectionTries
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | $logger->debug("connection try: $connectionTries ".Dumper($FTP)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | my $ssherr = File::Temp::tempfile() or $logger->error("couldn't open temp file for ftperrlog".longmess()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # separate setting of debug level, additional to "-v" verbose | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $Net::SFTP::Foreign::debug = $debugLevel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | ▶ | no warnings 'Net::SFTP::Foreign'; # suppress warning on using insecure password authentication with plink | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | $ftp = Net::SFTP::Foreign->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | host => $RemoteHost, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | user => $FTP->{user}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | password => $pwd, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | port => ($FTP->{port} ? $FTP->{port} : '22'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ssh_cmd => $FTP->{sshInstallationPath}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ssh_cmd_interface => 'plink', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | more => \@moreparams, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | ($FTP->{additionalParamsNew} ? %{$FTP->{additionalParamsNew}} : ()) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | $connectionTries++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | $ftp->error and do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $logger->warn("connection failed: ".$ftp->error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # after first failure set full debug ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | if ($connectionTries == 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $logger->warn("first call to Net::SFTP::Foreign->new failed, redoing with full debug and verbose setting.."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | push @moreparams, "-v"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $debugLevel = 1|2|4|8|16|32|64|128|256|4096|8192|16384|32768; # exclude hexdumps (bits 10 and 11) and sensitive information (bit 16) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $debugLevel = $FTP->{FTPdebugLevel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } until (!$ftp->error or $connectionTries == $maxConnectionTries); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if ($connectionTries == $maxConnectionTries and $ftp->error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$connectionTries == $maxConnectionTries and $ftp->error
MC/DC0%0/2
$connectionTries == $maxConnectionTries and $ftp->error
$connectionTries == $maxConnectionTries
$ftp->error
Truth table0%0/3
A and B
A= $connectionTries == $maxConnectionTriesB= $ftp->error
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $logger->error("connection finally failed after $maxConnectionTries connection tries: ".$ftp->error.longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | undef $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $logger->info("connecting to $RemoteHost using standard FTP (neither defined \$FTP->{hostkey} nor defined \$FTP->{privKey} nor set \$FTP->{SFTP})"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $logger->debug("FTP parameters:".Dumper($FTP)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $connectionTries = 0; my $loginSuccess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$loginSuccess or $connectionTries == $maxConnectionTries
MC/DC0%0/2
$loginSuccess or $connectionTries == $maxConnectionTries
$loginSuccess
$connectionTries == $maxConnectionTries
Truth table0%0/3
A or B
A= $loginSuccessB= $connectionTries == $maxConnectionTries
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | $ftp = Net::FTP->new($RemoteHost,Debug => $FTP->{FTPdebugLevel}, Port => ($FTP->{port} ? $FTP->{port} : '21')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if (! defined($ftp)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $logger->error("connection to ".$RemoteHost." failed, reason: $@ $!".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $loginSuccess = $ftp->login($FTP->{user},$FTP->{pwd}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if (!$loginSuccess) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $logger->error("login failed, reason: ".$ftp->message.longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | undef $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | $connectionTries++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } until ($loginSuccess or $connectionTries == $maxConnectionTries); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if ($connectionTries == $maxConnectionTries and !$loginSuccess) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$connectionTries == $maxConnectionTries and not $loginSuccess
MC/DC0%0/2
$connectionTries == $maxConnectionTries and not $loginSuccess
$connectionTries == $maxConnectionTries
not $loginSuccess
Truth table0%0/3
A and not(B)
A= $connectionTries == $maxConnectionTriesB= not $loginSuccess
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $logger->error("connection finally failed after $maxConnectionTries connection tries".longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | undef $ftp; $ftpHandles{$RemoteHost} = $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | if (defined($FTP->{type})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | if ($FTP->{type} eq "A") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if (!$ftp->ascii()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | $logger->error("can't switch to ascii, reason: ".$ftp->message.longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | undef $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if (!$ftp->binary()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | $logger->error("can't switch to binary, reason: ".$ftp->message.longmess()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | undef $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | if (!$ftp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $ftpHandles{$RemoteHost} = $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $ftpHandles{$RemoteHost} = $ftp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | $logger->info("login successful, ftp connection established"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # set handle with externally created Net::FTP or Net::SFTP::Foreign handle (if EAI::FTP::login capabilities are not sufficient) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | sub setHandle ($;$) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setHandle: not called CC=7 SCAR=40.3
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my ($handle,$rhost) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $logger = get_logger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | confess "neither Net::SFTP::Foreign nor Net::FTP handle passed to setHandle, argument is '".(defined($handle) ? ref($handle) : "undefined")."'" unless $handle and blessed $handle and ($handle->isa('Net::SFTP::Foreign') or $handle->isa('Net::FTP')) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$handle and builtin::blessed($handle) and $handle->isa("Net::SFTP::Foreign") || $handle->isa("Net::FTP")
$handle and builtin::blessed($handle)
$handle->isa("Net::SFTP::Foreign") or $handle->isa("Net::FTP")
MC/DC0%0/4
$handle and builtin::blessed($handle) and $handle->isa("Net::SFTP::Foreign") || $handle->isa("Net::FTP")
$handle
builtin::blessed($handle)
$handle->isa("Net::SFTP::Foreign")
$handle->isa("Net::FTP")
Truth table0%0/5
A and B and C or D
A= $handleB= builtin::blessed($handle)C= $handle->isa("Net::SFTP::Foreign")D= $handle->isa("Net::FTP")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | $ftp = $handle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $RemoteHost = $rhost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | $logger->error($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # used to get the raw ftp handler, mainly for testability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | sub getHandle { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getHandle: not called CC=1 SCAR=6.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | return ($ftp, $RemoteHost); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 2 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||