FTP.pm

filter: Statementstmt 13.5% 59 / 435 Branchbran 0.3% 1 / 306 Conditioncond 0.0% 0 / 135 MC/DCmcdc 0.0% 0 / 84 Subroutinesub 50.0% 19 / 38 Podpod 100% 9 / 9 totaltotal 8.7% 88 / 1007 CC 206 SCAR 67.1
CC
206
Cov
7%
login
2346.1
archiveFiles
992.0
fetchFiles
702.8
CRAP 819.8
↑ Summary Common.pm »
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
BranchTrueFalseTotal
if ($^O =~ /MSWin/u) 0 2 2
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
33 0 ▶ return $ftp->get($remoteFile, $localFile, queue_size => $queue_size, ($additionalParams ? %$additionalParams : ()));
Branch: 1 branch
BranchTrueFalseTotal
$additionalParams ? : 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
45 0 my @returnedFiles = $ftp->glob($remoteFile, names_only => 1);
46 0 ▶ if ($withoutPath and $remoteGlob) {
Branch: 1 branch
BranchTrueFalseTotal
if ($withoutPath and $remoteGlob) { } 0 0 0
Condition0%0/3
$withoutPath and $remoteGlob
!ll&&!rl&&r
000
MC/DC0%0/2
$withoutPath and $remoteGlob
$withoutPath $remoteGlob
Truth table0%0/3
A and B
A= $withoutPathB= $remoteGlob
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($remoteGlob eq "") 0 0 0
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
BranchTrueFalseTotal
$remotePath eq '.' || $withoutPath ? : 0 0 0
Condition0%0/3
$remotePath eq "." or $withoutPath
l!l&&r!l&&!r
000
MC/DC0%0/2
$remotePath eq "." or $withoutPath
$remotePath eq "." $withoutPath
Truth table0%0/3
A or B
A= $remotePath eq "."B= $withoutPath
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
if $logger->is_trace 0 0 0
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)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $logger->is_trace 0 0 0
80 0 my %file = (filename => $file);
81 0 ▶ push @$matchedFiles, \%file if $ftp->mdtm($file) < $mtimeToKeep;
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->mdtm($file) < $mtimeToKeep 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
91 0 my $attr = $ftp->stat($remoteFile);
92 0 ▶ return $attr->mtime if $attr;
Branch: 1 branch
BranchTrueFalseTotal
if $attr 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
$additionalParams ? : 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
if ($ftp->isa('Net::SFTP::Foreign')) { } 0 0 0
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
BranchTrueFalseTotal
if $param->{"remove"}{"removeFolders"} 0 0 0
145 0 ▶ if (defined $ftp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ftp) { } 0 0 0
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
BranchTrueFalseTotal
$param->{'remoteDir'} ? : 0 0 0
151 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
152 0 ▶ if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($param->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
154 }
155 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
156 0 ▶ if (_setcwd($remoteDir.$folder)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir . $folder)) { } 0 0 0
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
BranchTrueFalseTotal
my $files = &_ls_age($mtimeToKeep) or $logger->error(q[can't get file list, reason: ] . &_error() . ', status: ' . &_status() . longmess()) 0 0 0
159 0 for my $file (@$files) {
160 0 ▶ $logger->info("$remoteDir$folder:".($param->{simulate} ? "simulate removal of: " : "removing: ").$file->{filename});
Branch: 1 branch
BranchTrueFalseTotal
$param->{'simulate'} ? : 0 0 0
161 0 ▶ unless ($param->{simulate}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->{"simulate"}) 0 0 0
162 0 ▶ _remove($file->{filename}) or $logger->error("can't remove $file->{filename}: "._error().", status: "._status().longmess());
Branch: 1 branch
BranchTrueFalseTotal
&_remove($file->{"filename"}) or $logger->error(qq[can't remove $file->{"filename"}: ] . &_error() . ', status: ' . &_status() . longmess()) 0 0 0
163 }
164 }
165 0 ▶ $logger->info("$remoteDir$folder: no Files to remove !") if !@$files;
Branch: 1 branch
BranchTrueFalseTotal
unless @$files 0 0 0
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'}
l!l&&r!l&&!r
000
$FTP->{"fileToRemove"} || $FTP->{"fileToArchive"} and $param->{"firstRunSuccess"}
!ll&&!rl&&r
000
$FTP->{"fileToRemove"} or $FTP->{"fileToArchive"}
l!l&&r!l&&!r
000
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'}
ABCDresult
1X1X1
011X1
00X11
1X011
01011
00X00
1X000
01000
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
BranchTrueFalseTotal
unless $queue_size 0 0 0
187 0 ▶ if (defined $ftp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ftp) { } 0 0 0
188 0 ▶ my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : "");
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'remoteDir'} ? : 0 0 0
189 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
190 0 ▶ if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($FTP->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
192 }
193 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
194 0 ▶ if (_setcwd($remoteDir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir)) { } 0 0 0
195 0 $logger->debug("changed into $remoteDir");
196 0 ▶ my $remoteFile = ($FTP->{path} ? $FTP->{path}."/" : "").$param->{fileToRetrieve};
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'path'} ? : 0 0 0
197 0 ▶ my $localPath = ($FTP->{localDir} ? $FTP->{localDir} : $param->{homedir});
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'localDir'} ? : 0 0 0
198 0 ▶ $localPath .= "/" if $localPath !~ /.*[\/\\]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $localPath =~ m(.*[/\\]$)u 0 0 0
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
BranchTrueFalseTotal
if ($remoteFile =~ /\*/u) { } 0 0 0
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
BranchTrueFalseTotal
if ($i < @multipleFiles) 0 0 0
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
BranchTrueFalseTotal
&_get($multipleRemoteFiles[$i], $localPath . $multipleFiles[$i], $queue_size, $FTP->{"additionalParamsGet"}) or do { unless (&_error() == 11) { if ($suppressGetError) { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} $logger->debug(q[can't get remote-file ] . $multipleRemoteFiles[$i] . ', reason: ' . &_error() . ', error message suppressed because of $param{firstRunSuccess}(' . $param->{"firstRunSuccess"} . ') or $param{fileToRetrieveOptional}(' . $param->{"fileToRetrieveOptional"} . ')'); } else { $logger->error(q[error: can't get remote-file ] . $multipleRemoteFiles[$i] . " from glob $remoteFile, reason: " . &_error() . ', status: ' . &_status() . longmess()); } ; @{$$param{"retrievedFiles"};} = (); return 0; } } 0 0 0
209 0 ▶ unless (_error() == SFTP_ERR_LOCAL_UTIME_FAILED) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_error() == 11) 0 0 0
210 0 ▶ if ($suppressGetError) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suppressGetError) { } 0 0 0
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
BranchTrueFalseTotal
&_get($remoteFile, $localFile, $queue_size, $FTP->{"additionalParamsGet"}) or do { unless (&_error() == 11) { if ($suppressGetError) { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} $logger->debug("can't get remote-file $remoteFile, reason: " . &_error() . ', error message suppressed because of $param{firstRunSuccess}(' . $param->{"firstRunSuccess"} . ') or $param{fileToRetrieveOptional}(' . $param->{"fileToRetrieveOptional"} . ')'); } else { $logger->error("can't get remote-file $remoteFile, reason: " . &_error() . ', status: ' . &_status() . longmess()); } ; @{$$param{"retrievedFiles"};} = (); return 0; } } 0 0 0
229 0 ▶ unless (_error() == SFTP_ERR_LOCAL_UTIME_FAILED) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_error() == 11) 0 0 0
230 0 ▶ if ($suppressGetError) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suppressGetError) { } 0 0 0
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
BranchTrueFalseTotal
if ($mod_time and not $FTP->{"dontDoUtime"}) 0 0 0
Condition0%0/3
$mod_time and not $FTP->{"dontDoUtime"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
242 0 ▶ utime($mod_time,$mod_time,$localFile) or $logger->warn("couldn't set time for $localFile: $!");
Branch: 1 branch
BranchTrueFalseTotal
utime $mod_time, $mod_time, $localFile or $logger->warn("couldn't set time for ${localFile}: $!") 0 0 0
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
BranchTrueFalseTotal
if $param->{"filesToWrite"} and ref $param->{"filesToWrite"} eq "ARRAY" 0 0 0
Condition0%0/3
$param->{"filesToWrite"} and ref $param->{"filesToWrite"} eq "ARRAY"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
262 0 ▶ $localFile = $param->{fileToWrite} if $param->{fileToWrite};
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"fileToWrite"} 0 0 0
263 0 ▶ if (!$localFile and @localFiles == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $localFile and @localFiles == 0) 0 0 0
Condition0%0/3
not $localFile and @localFiles == 0
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $localFile 0 0 0
268 0 ▶ if (defined $ftp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ftp) { } 0 0 0
269 0 ▶ my $doSetStat = ($FTP->{dontDoSetStat} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'dontDoSetStat'} ? : 0 0 0
270 0 ▶ my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : "");
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'remoteDir'} ? : 0 0 0
271 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
272 0 ▶ if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($FTP->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
274 }
275 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
276 0 ▶ if (_setcwd($remoteDir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir)) { } 0 0 0
277 0 $logger->debug("changed into $remoteDir");
278 0 for $localFile (@localFiles) {
279 0 ▶ if ($FTP->{dontUseTempFile}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FTP->{'dontUseTempFile'}) { } 0 0 0
280 0 $logger->info("uploading file $localFile \$doSetStat: $doSetStat");
281 0 ▶ if (!_put($localFile, $doSetStat, $FTP->{additionalParamsPut})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_put($localFile, $doSetStat, $FTP->{"additionalParamsPut"})) 0 0 0
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
BranchTrueFalseTotal
rename $localFile, 'temp.' . $localFile or $logger->error("can't rename local file $localFile to temp.$localFile, reason: $!" . longmess()) 0 0 0
289 0 $logger->info("uploading file temp.$localFile, \$doSetStat: $doSetStat");
290 0 ▶ if (!_put("temp.$localFile", $doSetStat, $FTP->{additionalParamsPut})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_put("temp.$localFile", $doSetStat, $FTP->{"additionalParamsPut"})) 0 0 0
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
BranchTrueFalseTotal
unless ($FTP->{"dontMoveTempImmediately"}) 0 0 0
297 0 $logger->debug("Sftp: remote rename temp file temp.$localFile auf $localFile ...");
298 0 ▶ if ($ftp->rename("temp.".$localFile,$localFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->rename('temp.' . $localFile, $localFile)) { } 0 0 0
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
BranchTrueFalseTotal
$FTP->{'dontUseTempFile'} ? : 0 0 0
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
BranchTrueFalseTotal
my $localFile = $param->{"fileToWrite"} or do { $logger->error('no file to upload (fileToWrite parameter) !' . longmess()); return 0 } 0 0 0
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
BranchTrueFalseTotal
if (defined $ftp) { } 0 0 0
330 0 ▶ my $remoteDir = ($FTP->{remoteDir} ? $FTP->{remoteDir} : "");
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'remoteDir'} ? : 0 0 0
331 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
332 0 ▶ if (substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($FTP->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
334 }
335 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $FTP->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $FTP->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
336 0 ▶ if (_setcwd($remoteDir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir)) { } 0 0 0
337 0 $logger->debug("changed into $remoteDir");
338 0 ▶ if ($ftp->rename("temp.".$localFile,$localFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->rename('temp.' . $localFile, $localFile)) { } 0 0 0
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
BranchTrueFalseTotal
if $param->{"filesToArchive"} 0 0 0
360 0 my $archiveTimestamp = $param->{timestamp};
361 0 ▶ $archiveTimestamp = get_curdatetime()."." if !defined($param->{timestamp});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param->{"timestamp"} 0 0 0
362 0 ▶ if (defined $ftp and @filesToArchive) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ftp and @filesToArchive) { } 0 0 0
Condition0%0/3
defined $ftp and @filesToArchive
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ftp and @filesToArchive
defined $ftp @filesToArchive
Truth table0%0/3
A and B
A= defined $ftpB= @filesToArchive
ABresult
0X0
100
111
363 0 $logger->info("archiving files @filesToArchive");
364 0 ▶ my $remoteDir = ($param->{remoteDir} ? $param->{remoteDir} : "");
Branch: 1 branch
BranchTrueFalseTotal
$param->{'remoteDir'} ? : 0 0 0
365 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
366 0 ▶ if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($param->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
368 }
369 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
370 0 ▶ my $archiveDir = ((substr($param->{archiveDir},-1) eq "/" || $param->{archiveDir} eq "") ? $param->{archiveDir} : $param->{archiveDir}."/") if $param->{archiveDir}; $archiveDir.="";
Branch: 2 branches
BranchTrueFalseTotal
if $param->{"archiveDir"} 0 0 0
substr($param->{'archiveDir'}, -1) eq '/' || $param->{'archiveDir'} eq '' ? : 0 0 0
Condition0%0/3
substr($param->{"archiveDir"}, -1) eq "/" or $param->{"archiveDir"} eq ""
l!l&&r!l&&!r
000
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 ""
ABresult
1X1
011
000
371 0 ▶ if (_setcwd($remoteDir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir)) { } 0 0 0
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
BranchTrueFalseTotal
$archiveDir ? : 0 0 0
375 0 ▶ if ($remoteFile =~ /\*/) { # if glob character contained, then move multiple files
Branch: 1 branch
BranchTrueFalseTotal
if ($remoteFile =~ /\*/u) { } 0 0 0
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
BranchTrueFalseTotal
if $specFileNameOnly eq "" 0 0 0
381 0 ▶ if ($ftp->rename($specFile,$specFilePathOnly.$archiveDir.$archiveTimestamp.$specFileNameOnly)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->rename($specFile, $specFilePathOnly . $archiveDir . $archiveTimestamp . $specFileNameOnly)) { } 0 0 0
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
BranchTrueFalseTotal
unless $errmsg =~ /No such file or directory/u 0 0 0
386 0 ▶ $logger->warn("error: $errmsg".longmess()) if $errmsg =~ /No such file or directory/;
Branch: 1 branch
BranchTrueFalseTotal
if $errmsg =~ /No such file or directory/u 0 0 0
387 }
388 }
389 } else {
390 0 ▶ if ($ftp->rename($remoteFile,$archiveDir.$archiveTimestamp.$remoteFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->rename($remoteFile, $archiveDir . $archiveTimestamp . $remoteFile)) { } 0 0 0
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
BranchTrueFalseTotal
unless $errmsg =~ /no such file or directory/iu or $errmsg =~ /does not exist/iu 0 0 0
Condition0%0/3
$errmsg =~ /no such file or directory/iu or $errmsg =~ /does not exist/iu
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
395 0 ▶ $logger->warn("error: $errmsg".longmess()) if $errmsg =~ /no such file or directory/i or $errmsg !~ /does not exist/i;
Branch: 1 branch
BranchTrueFalseTotal
if $errmsg =~ /no such file or directory/iu or not $errmsg =~ /does not exist/iu 0 0 0
Condition0%0/3
$errmsg =~ /no such file or directory/iu or not $errmsg =~ /does not exist/iu
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $ftp 0 0 0
404 0 ▶ $logger->error("no files to archive given".longmess()) unless @filesToArchive;
Branch: 1 branch
BranchTrueFalseTotal
unless @filesToArchive 0 0 0
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
BranchTrueFalseTotal
if $param->{"filesToRemove"} 0 0 0
415 0 ▶ if (defined $ftp and @filesToRemove) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ftp and @filesToRemove) { } 0 0 0
Condition0%0/3
defined $ftp and @filesToRemove
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ftp and @filesToRemove
defined $ftp @filesToRemove
Truth table0%0/3
A and B
A= defined $ftpB= @filesToRemove
ABresult
0X0
100
111
416 0 $logger->info("removing files @filesToRemove");
417 0 ▶ my $remoteDir = ($param->{remoteDir} ? $param->{remoteDir} : "");
Branch: 1 branch
BranchTrueFalseTotal
$param->{'remoteDir'} ? : 0 0 0
418 0 ▶ $logger->debug(($remoteDir ? "changing into ".$remoteDir : "remaining in home"));
Branch: 1 branch
BranchTrueFalseTotal
$remoteDir ? : 0 0 0
419 0 ▶ if (substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange}) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}) 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
&_setcwd(undef) or $logger->error(q[can't change into home ($param->{noDirectRemoteDirChange} is set, first changing to home)] . longmess()) 0 0 0
421 }
422 0 ▶ $remoteDir = substr($remoteDir,1) if substr($remoteDir,0,1) eq "/" and $param->{noDirectRemoteDirChange};
Branch: 1 branch
BranchTrueFalseTotal
if substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"} 0 0 0
Condition0%0/3
substr($remoteDir, 0, 1) eq "/" and $param->{"noDirectRemoteDirChange"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
423 0 ▶ if (_setcwd($remoteDir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_setcwd($remoteDir)) { } 0 0 0
424 0 $logger->debug("changed into $remoteDir");
425 0 for my $remoteFile (@filesToRemove) {
426 0 ▶ if (_remove($remoteFile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_remove($remoteFile)) { } 0 0 0
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
BranchTrueFalseTotal
unless $errmsg =~ /no such file/iu or $errmsg =~ /does not exist/iu 0 0 0
Condition0%0/3
$errmsg =~ /no such file/iu or $errmsg =~ /does not exist/iu
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $errmsg =~ /no such file/iu or not $errmsg =~ /does not exist/iu 0 0 0
Condition0%0/3
$errmsg =~ /no such file/iu or not $errmsg =~ /does not exist/iu
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $ftp 0 0 0
439 0 ▶ $logger->error("no files to remove given".longmess()) unless @filesToRemove;
Branch: 1 branch
BranchTrueFalseTotal
unless @filesToRemove 0 0 0
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
BranchTrueFalseTotal
$setRemoteHost or do { $logger->error('remote host not set in $setRemoteHost' . longmess()); return 0 } 0 0 0
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
BranchTrueFalseTotal
if (not defined $ftpHandles{$RemoteHost} or defined $enforceConn and $enforceConn) { } 0 0 0
Condition0%0/6
not defined $ftpHandles{$RemoteHost} or defined $enforceConn and $enforceConn
l!l&&r!l&&!r
000
defined $enforceConn and $enforceConn
!ll&&!rl&&r
000
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
ABCresult
1XX1
0111
00X0
0100
455 0 ▶ $logger->debug((defined($enforceConn) && $enforceConn ? "enforceConn is defined" : "ftp connection doesn't exist").", creating new ftp connection");
Branch: 1 branch
BranchTrueFalseTotal
defined $enforceConn && $enforceConn ? : 0 0 0
Condition0%0/3
defined $enforceConn and $enforceConn
!ll&&!rl&&r
000
MC/DC0%0/2
defined $enforceConn and $enforceConn
defined $enforceConn $enforceConn
Truth table0%0/3
A and B
A= defined $enforceConnB= $enforceConn
ABresult
0X0
100
111
456 0 ▶ undef $ftpHandles{$RemoteHost} if defined($ftpHandles{$RemoteHost}); # close ftp connection if open.
Branch: 1 branch
BranchTrueFalseTotal
if defined $ftpHandles{$RemoteHost} 0 0 0
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
BranchTrueFalseTotal
if (&_setcwd(undef)) { } 0 0 0
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
BranchTrueFalseTotal
if ($^O =~ /MSWin/u and not $FTP->{"dontUseQuoteSystemForPwd"}) 0 0 0
Condition0%0/3
$^O =~ /MSWin/u and not $FTP->{"dontUseQuoteSystemForPwd"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
474 0 ▶ $pwd = Win32::ShellQuote::quote_system($pwd) if ($pwd and $pwd =~ /[()"<>&]/);
Branch: 1 branch
BranchTrueFalseTotal
if $pwd and $pwd =~ /[()"<>&]/u 0 0 0
Condition0%0/3
$pwd and $pwd =~ /[()"<>&]/u
!ll&&!rl&&r
000
MC/DC0%0/2
$pwd and $pwd =~ /[()"<>&]/u
$pwd $pwd =~ /[()"<>&]/u
Truth table0%0/3
A and B
A= $pwdB= $pwd =~ /[()"<>&]/u
ABresult
0X0
100
111
475 }
476 0 my $debugLevel = $FTP->{FTPdebugLevel};
477 0 ▶ if (defined($FTP->{hostkey}) || defined($FTP->{privKey}) || $FTP->{SFTP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $FTP->{'hostkey'} or defined $FTP->{'privKey'} or $FTP->{'SFTP'}) { } 0 0 0
Condition0%0/6
defined $FTP->{"hostkey"} or defined $FTP->{"privKey"} or $FTP->{"SFTP"}
l!l&&r!l&&!r
000
defined $FTP->{"hostkey"} or defined $FTP->{"privKey"}
l!l&&r!l&&!r
000
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"}
ABCresult
1XX1
01X1
0011
0000
478 0 ▶ if (!$FTP->{sshInstallationPath}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($FTP->{"sshInstallationPath"}) 0 0 0
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
BranchTrueFalseTotal
unless (defined $FTP->{"pwd"} or $FTP->{"privKey"}) 0 0 0
Condition0%0/3
defined $FTP->{"pwd"} or $FTP->{"privKey"}
l!l&&r!l&&!r
000
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"}
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($FTP->{"additionalParamsNew"} and ref $FTP->{"additionalParamsNew"} ne "HASH") 0 0 0
Condition0%0/3
$FTP->{"additionalParamsNew"} and ref $FTP->{"additionalParamsNew"} ne "HASH"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($FTP->{"additionalMoreArgs"} and ref $FTP->{"additionalMoreArgs"} ne "ARRAY") 0 0 0
Condition0%0/3
$FTP->{"additionalMoreArgs"} and ref $FTP->{"additionalMoreArgs"} ne "ARRAY"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $debugLevel 0 0 0
497 0 ▶ push @moreparams, ("-hostkey", $FTP->{hostkey}) if $FTP->{hostkey};
Branch: 1 branch
BranchTrueFalseTotal
if $FTP->{"hostkey"} 0 0 0
498 0 ▶ push @moreparams, ("-hostkey", $FTP->{hostkey2}) if $FTP->{hostkey2};
Branch: 1 branch
BranchTrueFalseTotal
if $FTP->{"hostkey2"} 0 0 0
499 0 ▶ push @moreparams, ("-i", $FTP->{privKey}) if $FTP->{privKey};
Branch: 1 branch
BranchTrueFalseTotal
if $FTP->{"privKey"} 0 0 0
500 0 ▶ push @moreparams, @{$FTP->{additionalMoreArgs}} if $FTP->{additionalMoreArgs};
Branch: 1 branch
BranchTrueFalseTotal
if $FTP->{"additionalMoreArgs"} 0 0 0
501 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
(not $ftp->error or $connectionTries == $maxConnectionTries) or do { do { $logger->debug("connection try: $connectionTries " . Dumper($FTP)); my $ssherr = File::Temp::tempfile() or $logger->error(q[couldn't open temp file for ftperrlog] . longmess()); $Net::SFTP::Foreign::debug = $debugLevel; BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x45\x55"} $ftp = "Net::SFTP::Foreign"->new("host", $RemoteHost, "user", $FTP->{"user"}, "password", $pwd, "port", $FTP->{"port"} ? $FTP->{"port"} : 22, "ssh_cmd", $FTP->{"sshInstallationPath"}, "ssh_cmd_interface", "plink", "more", \@moreparams, $FTP->{"additionalParamsNew"} ? %{$$FTP{"additionalParamsNew"};} : ()); ++$connectionTries; $ftp->error and do { $logger->warn('connection failed: ' . $ftp->error); if ($connectionTries == 1) { $logger->warn("first call to Net::SFTP::Foreign->new failed, redoing with full debug and verbose setting.."); push @moreparams, "-v"; $debugLevel = 61951; } else { $debugLevel = $FTP->{"FTPdebugLevel"}; } } } } 0 0 0
Condition0%0/3
not $ftp->error or $connectionTries == $maxConnectionTries
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
my $ssherr = File::Temp::tempfile() or $logger->error(q[couldn't open temp file for ftperrlog] . longmess()) 0 0 0
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
BranchTrueFalseTotal
$FTP->{'port'} ? : 0 0 0
$FTP->{'additionalParamsNew'} ? : 0 0 0
516 );
517 0 $connectionTries++;
518 0 ▶ $ftp->error and do {
Branch: 1 branch
BranchTrueFalseTotal
$ftp->error and do { $logger->warn('connection failed: ' . $ftp->error); if ($connectionTries == 1) { $logger->warn("first call to Net::SFTP::Foreign->new failed, redoing with full debug and verbose setting.."); push @moreparams, "-v"; $debugLevel = 61951; } else { $debugLevel = $FTP->{"FTPdebugLevel"}; } } 0 0 0
519 0 $logger->warn("connection failed: ".$ftp->error);
520 # after first failure set full debug ...
521 0 ▶ if ($connectionTries == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($connectionTries == 1) { } 0 0 0
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
BranchTrueFalseTotal
if ($connectionTries == $maxConnectionTries and $ftp->error) 0 0 0
Condition0%0/3
$connectionTries == $maxConnectionTries and $ftp->error
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
($loginSuccess or $connectionTries == $maxConnectionTries) or do { do { $ftp = "Net::FTP"->new($RemoteHost, "Debug", $FTP->{"FTPdebugLevel"}, "Port", $FTP->{"port"} ? $FTP->{"port"} : 21); if (not defined $ftp) { $logger->error('connection to ' . $RemoteHost . " failed, reason: $@ $!" . longmess()); } else { $loginSuccess = $ftp->login($FTP->{"user"}, $FTP->{"pwd"}); unless ($loginSuccess) { $logger->error('login failed, reason: ' . $ftp->message . longmess()); undef $ftp; } ; } ; ++$connectionTries } } 0 0 0
Condition0%0/3
$loginSuccess or $connectionTries == $maxConnectionTries
l!l&&r!l&&!r
000
MC/DC0%0/2
$loginSuccess or $connectionTries == $maxConnectionTries
$loginSuccess $connectionTries == $maxConnectionTries
Truth table0%0/3
A or B
A= $loginSuccessB= $connectionTries == $maxConnectionTries
ABresult
1X1
011
000
540 0 ▶ $ftp = Net::FTP->new($RemoteHost,Debug => $FTP->{FTPdebugLevel}, Port => ($FTP->{port} ? $FTP->{port} : '21'));
Branch: 1 branch
BranchTrueFalseTotal
$FTP->{'port'} ? : 0 0 0
541 0 ▶ if (! defined($ftp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ftp) { } 0 0 0
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
BranchTrueFalseTotal
unless ($loginSuccess) 0 0 0
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
BranchTrueFalseTotal
if ($connectionTries == $maxConnectionTries and not $loginSuccess) 0 0 0
Condition0%0/3
$connectionTries == $maxConnectionTries and not $loginSuccess
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (defined $FTP->{"type"}) 0 0 0
558 0 ▶ if ($FTP->{type} eq "A") {
Branch: 1 branch
BranchTrueFalseTotal
if ($FTP->{'type'} eq 'A') { } 0 0 0
559 0 ▶ if (!$ftp->ascii()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->ascii) 0 0 0
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
BranchTrueFalseTotal
unless ($ftp->binary) 0 0 0
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
BranchTrueFalseTotal
unless ($ftp) 0 0 0
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
BranchTrueFalseTotal
unless $handle and builtin::blessed($handle) and $handle->isa("Net::SFTP::Foreign") || $handle->isa("Net::FTP") 0 0 0
defined $handle ? : 0 0 0
Condition0%0/9
$handle and builtin::blessed($handle) and $handle->isa("Net::SFTP::Foreign") || $handle->isa("Net::FTP")
!ll&&!rl&&r
000
$handle and builtin::blessed($handle)
!ll&&!rl&&r
000
$handle->isa("Net::SFTP::Foreign") or $handle->isa("Net::FTP")
l!l&&r!l&&!r
000
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")
ABCDresult
0XXX0
10XX0
11000
111X1
11011
586 0 $ftp = $handle;
587 0 $RemoteHost = $rhost;
588 };
589 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
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__
↑ Summary Common.pm »