FTP.pm

filter: Statementstmt 14.6% 50 / 341 Branchbran 0.0% 0 / 168 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 21.1% 11 / 52 Podpod 0.0% 0 / 43 totaltotal 9.7% 61 / 629 CC 90 SCAR 51.0
CC
90
Cov
10%
getslurp
460.2
putblat
306.0
open
185.2
CRAP 164.2
↑ Summary example.pl »
1 package Net::Lite::FTP;
2  
3  
4 1 ▶use 5.006000;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our @ISA = qw(Exporter);
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16  
17 # This allows declaration use Net::Lite::FTP ':all';
18 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19 # will save memory.
20 1 our %EXPORT_TAGS = ( 'all' => [ qw(
21  
22 ) ] );
23  
24 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25  
26 1 our @EXPORT = qw(
27  
28 );
29  
30 1 our $VERSION = '0.61';
31 # Preloaded methods go here.
32 # Autoload methods go after =cut, and are processed by the autosplit program.
33 1 ▶use constant BUFSIZE => 4096;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 BEGIN {
35 1 ▶ use Net::SSLeay::Handle qw/shutdown/;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 # You only need this if your FTP server requires client certs:
37 #Net::SSLeay::Handle::_set_cert("/home/eyck/my.pem");
38 #Net::SSLeay::Handle::_set_key("/home/eyck/my.pem");
39 # but if you want this, you need to patch your Net::SSLeay,
40 };
41  
42 sub new($$) {
43 1 ▶ my $class=shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
44 1 my $self={};
45 1 bless $self,$class;
46 # $self->{'DBHandle'}=$dbh;
47 1 $self->{"CreationTime"}=time;
48 1 $self->{"Connected"}=0;
49 1 $self->{"EncryptData"}=1;
50 1 $self->{"Encrypt"}=1;
51 1 $self->{"Debug"}=0;
52 1 $self->{"ErrMSG"}=undef;
53 1 $self->{"GetUpdateCallback"} = undef;
54 1 $self->{"GetDoneCallback"} = undef;
55 1 $self->{"PutUpdateCallback"} = undef;
56 1 $self->{"PutDoneCallback"} = undef;
57 1 return $self;
58 };
59  
60 sub user($$) {
61 0 ▶ my ($self,$user)=@_;
Subroutine user: not called CC=1 SCAR=6.9
Pod undocumented
62 0 $self->command("USER $user");
63 }
64 sub pass($$) {
65 0 ▶ my ($self,$pass)=@_;
Subroutine pass: not called CC=1 SCAR=6.9
Pod undocumented
66 0 $self->command("PASS $pass");
67 }
68 sub login($$$) {
69 0 ▶ my ($self,$user,$pass)=@_;
Subroutine login: not called CC=1 SCAR=6.9
Pod undocumented
70 0 $self->command("USER $user");
71 0 $self->command("PASS $pass");
72 }
73  
74 sub cwd ($$) {
75 0 ▶ my ($self,$data)=@_;
Subroutine cwd: not called CC=1 SCAR=6.9
Pod undocumented
76 0 $self->command("CWD $data");
77 }
78 sub mkdir ($$) {
79 0 ▶ my ($self,$data)=@_;
Subroutine mkdir: not called CC=1 SCAR=6.9
Pod undocumented
80 0 $self->command("MKD $data");
81 }
82 sub rmdir ($$) {
83 0 ▶ my ($self,$data)=@_;
Subroutine rmdir: not called CC=1 SCAR=6.9
Pod undocumented
84 0 $self->command("RMD $data");
85 }
86  
87 sub size ($$) {
88 0 ▶ my ($self,$filename)=@_;
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
89 0 ▶ my $size=$self->command("SIZE $filename");chop $size if defined($size);
Branch: 1 branch
BranchTrueFalseTotal
if defined $size 0 0 0
90 0 return $size;
91 }
92 sub cdup ($$) {
93 0 ▶ my ($self,$data)=@_;
Subroutine cdup: not called CC=1 SCAR=6.9
Pod undocumented
94 0 $self->command("CDUP");
95 }
96 sub dele {
97 0 ▶ my ($self,$pathname)=@_;
Subroutine dele: not called CC=2 SCAR=17.9
Pod undocumented
98 0 ▶ return undef unless defined($pathname);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pathname 0 0 0
99 0 $self->command("DELE $pathname");
100 }
101 0 ▶sub rm {dele(@_);};
Subroutine rm: not called CC=1 SCAR=6.9
Pod undocumented
102 0 ▶sub delete {dele(@_);};
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
103 0 ▶sub del { shift->del(@_) };
Subroutine del: not called CC=1 SCAR=6.9
Pod undocumented
104  
105 sub rawmessage ($) {
106 0 ▶ my ($self)=@_;
Subroutine rawmessage: not called CC=1 SCAR=6.9
Pod undocumented
107 0 return $self->{'FTPRAWMSG'};
108 };
109 sub message ($) {
110 0 ▶ my ($self)=@_;
Subroutine message: not called CC=1 SCAR=6.9
Pod undocumented
111 0 return $self->{'FTPMSG'};
112 };
113 sub msgcode ($) {
114 0 ▶ my ($self)=@_;
Subroutine msgcode: not called CC=1 SCAR=6.9
Pod undocumented
115 0 return $self->{'FTPCODE'};
116 };
117  
118 sub readln {
119 0 ▶ my ($sock)=@_;
Subroutine readln: not called CC=4 SCAR=30.0
Pod undocumented
120 0 my ($data,$ln);
121 0 ▶ if (sysread($sock,$data,BUFSIZE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $sock, $data, 4096) 0 0 0
122 0 $ln=$data;
123 0 ▶ while ($data!~/\n/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data =~ /\n/) 0 0 0
124 0 ▶ if (sysread($sock,$data,BUFSIZE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $sock, $data, 4096) 0 0 0
125 #print "OPEN..Received: {$data}\n";# if $self->{Debug};
126 0 $ln.=$data;
127 };
128 };
129 };
130 0 return $ln;
131 };
132  
133 0 ▶sub SOL_IP { 0; };
Subroutine SOL_IP: not called CC=1 SCAR=6.9
Pod undocumented
134 sub IP_TOS { 1; };
135  
136 sub open($$$) {
137 0 ▶ my ($self,$host,$port)=@_;
Subroutine open: not called CC=14 SCAR=52.2
Pod undocumented
138 0 my ($data);
139 my $sock;
140 0 $sock = Net::SSLeay::Handle->make_socket($host, $port);
141 0 $self->{'Sock'}=$sock;
142 0 $self->{'Host'}=$host;
143 0 $self->{'Port'}=$port;
144 #tmp
145 1 ▶ use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
146 #setsockopt($sock,&SOL_SOCKET,&SO_KEEPALIVE,undef,undef) || warn "setsockopt: $!";
147 0 ▶ setsockopt($sock, SOL_SOCKET, SO_SNDTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $sock, 1, 21, "\17\0\0\0\0\0\0\0" or die 'setsockopt' . $! 0 0 0
148 0 ▶ setsockopt($sock, SOL_SOCKET, SO_RCVTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $sock, 1, 20, "\17\0\0\0\0\0\0\0" or die 'setsockopt' . $! 0 0 0
149 0 ▶ setsockopt($sock, SOL_SOCKET, SO_KEEPALIVE, 1 ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $sock, 1, 9, 1 or die 'setsockopt' . $! 0 0 0
150 #setsockopt($sock, SOL_SOCKET, IP_TOS, IPTOS_LOWDELAY ) or die "setsockopt".$!;
151 #/usr/share/perl/5.8.4/Net/Ping.pm: setsockopt($self->{"fh"}, SOL_IP, IP_TOS(), pack("I*", $self->{'tos'}))
152 0 setsockopt($sock, SOL_IP, IP_TOS(), pack("I*",0x10 ));#LOWLATENCY
153  
154 #/usr/include/linux/ip.h:#define IPTOS_LOWDELAY 0x10
155 ##define IPTOS_THROUGHPUT 0x08
156 #define IPTOS_MINCOST 0x02
157 #/usr/share/perl/5.8.4/Net/Ping.pm: setsockopt($self->{"fh"}, SOL_IP, IP_TOS(), pack("I*", $self->{'tos'}))
158 #end tmp 2008-11-04
159  
160 #FTPS EXPLICIT:
161 0 ▶ if ($self->{'FTPS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FTPS"}) 0 0 0
162 #{tie(*S, "Net::SSLeay::Handle", $sock);$sock = \*S;};
163 # Unique glob?
164 0 {my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $sock);$sock = \*$io;};
165 }
166  
167  
168  
169 0 ▶ if ($data=readln($sock)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data = readln($sock)) 0 0 0
170 0 ▶ print STDERR "OPEN.Received: $data" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
171 0 $data=$self->responserest($data);
172 0 ▶ print STDERR "OPEN..Received: $data" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
173 }
174  
175 0 ▶ if ($self->{'Encrypt'} && (! $self->{'FTPS'} )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Encrypt"} and not $self->{"FTPS"}) 0 0 0
Condition0%0/3
$self->{"Encrypt"} and not $self->{"FTPS"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Encrypt"} and not $self->{"FTPS"}
$self->{"Encrypt"} not $self->{"FTPS"}
Truth table0%0/3
A and not(B)
A= $self->{"Encrypt"}B= not $self->{"FTPS"}
ABresult
0X0
100
111
176 0 $data="AUTH TLS\r\n";
177 0 syswrite($sock,$data);
178 0 ▶ if ($data=readln($sock)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data = readln($sock)) 0 0 0
179 0 ▶ print STDERR "Received: $data" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
180 }
181 }
182 0 $self->{'RAWSock'}=$sock;
183  
184 0 ▶ if ($self->{'Encrypt'} && (! $self->{'FTPS'} )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Encrypt"} and not $self->{"FTPS"}) 0 0 0
Condition0%0/3
$self->{"Encrypt"} and not $self->{"FTPS"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"Encrypt"} and not $self->{"FTPS"}
$self->{"Encrypt"} not $self->{"FTPS"}
Truth table0%0/3
A and not(B)
A= $self->{"Encrypt"}B= not $self->{"FTPS"}
ABresult
0X0
100
111
185 #{tie(*S, "Net::SSLeay::Handle", $sock);$sock = \*S;};
186 # Unique glob?
187 0 {my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $sock);$sock = \*$io;};
188 }
189  
190 0 $self->{'Sock'}=$sock;
191 0 {select($sock);$|=1;select(STDOUT);};#unbuffer socket
192  
193 0 $self->setup_protection();
194  
195 #
196 0 return 1;
197 }
198  
199 sub quit {
200 0 ▶ my ($self)=@_;
Subroutine quit: not called CC=1 SCAR=6.9
Pod undocumented
201 0 return $self->command("QUIT");
202 }
203 sub noop {
204 0 ▶ my ($self)=@_;
Subroutine noop: not called CC=1 SCAR=6.9
Pod undocumented
205 0 return $self->command("NOOP");
206 }
207 sub rename ($$$) {
208 0 ▶ my ($self,$from,$to)=@_;
Subroutine rename: not called CC=2 SCAR=17.9
Pod undocumented
209 #"RNFR plik1"
210 #"RNTO plik2"
211 0 ▶ if ($self->command("RNFR $from")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->command("RNFR $from")) { } 0 0 0
212 0 return $self->command("RNTO $to");
213 0 } else {return 0;};
214 };
215 sub mdtm ($$) {
216 0 ▶ my ($self,$file)=@_;
Subroutine mdtm: not called CC=1 SCAR=6.9
Pod undocumented
217 0 return $self->command("MDTM $file");
218 };
219  
220 sub command ($$){
221 0 ▶ my ($self,$data)=@_;
Subroutine command: not called CC=2 SCAR=17.9
Pod undocumented
222 0 ▶ print STDERR "Sending: ",$data."\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
223 0 my $sock=$self->{'Sock'};
224 0 print $sock $data."\r\n";
225 0 return $self->response();
226 }
227  
228 sub response ($) {
229 0 ▶ my ($self)=@_;
Subroutine response: not called CC=2 SCAR=17.9
Pod undocumented
230 0 my $sock=$self->{'Sock'};
231 0 my ($read,$resp,$code,$cont);
232 0 $read=($resp=<$sock>);
233 0 ▶ if (!defined($read)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $read) 0 0 0
234 0 warn "Damn! undefined response (err:$!) {H: ".$self->{'Host'}." P:".$self->{'Port'}."}\n";# unless defined($read);
235 0 $self->{'FTPCODE'}=undef;
236 0 $self->{'FTPMSG'}=undef;
237 0 $self->{'FTPRAWMSG'}=undef;
238 0 return undef;# unless defined($read);
239 };
240 0 return $self->responserest($read);
241 }
242  
243 sub responserest ($$) {
244 0 ▶ my ($self,$read)=@_;
Subroutine responserest: not called CC=13 SCAR=52.0
Pod undocumented
245 0 my $sock=$self->{'Sock'};
246 0 my ($resp,$code,$cont,$msg);
247 0 $resp=$read;
248 #UWAGA!
249 # wcale nieprawda to co nizej pisze. Jesli pierwsza linijka to \d\d\d-
250 # to odbierac linijki az do napotkania \d\d\d\s
251 # np:
252 # 226-EDI processing started
253 # 01 costam...
254 # 02 costam..
255 # 226 ...EDI processing complete
256  
257  
258 # Responsy maja format \d\d\d
259 # lub wielolinijkowe: \d\d\d-
260 0 ▶ print STDERR "SRV Response: $read" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
261 0 ▶ $read=~/^(\d\d\d)\s(.*)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
$read =~ /^(\d\d\d)\s(.*)/ and do { $code = $1; $msg = $2; chomp $msg } 0 0 0
262 0 $code=$1;$msg=$2;chomp($msg);
263 };
264 0 ▶ $read=~/^(\d\d\d)-(.*)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
$read =~ /^(\d\d\d)-(.*)/ and do { $cont = 1; $code = $1; $msg .= $2; print STDERR "wielolinijkowa odpowiedz z servera.." if $self->{"Debug"} } 0 0 0
265 0 $cont=1;$code=$1;$msg.=$2;
266 0 ▶ print STDERR "wielolinijkowa odpowiedz z servera.." if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
267 };
268 0 ▶ if ($read=~/^(\d\d\d)\s(.*)/m) {$cont=0;}; # wyjatek na wielolinijkowe na dziendobry
Branch: 1 branch
BranchTrueFalseTotal
if ($read =~ /^(\d\d\d)\s(.*)/m) 0 0 0
269 0 ▶ if ($cont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cont) 0 0 0
270 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$cont == 0 or do { do { $read = readline $sock; $resp .= $read; $read =~ /^(\d\d\d)-(.*)/ and do { $cont = 1; $code = $1; $msg .= $2 }; $read =~ /^(\d\d\d)\s(.*)/ and do { $cont = 0; $code = $1; $msg .= $2 }; print " ----> $read\n" if $self->{"Debug"} } } 0 0 0
271 0 $read=<$sock>;
272 0 $resp.=$read;
273 0 ▶ $read=~/^(\d\d\d)-(.*)/ && do {$cont=1;$code=$1;$msg.=$2;};
Branch: 1 branch
BranchTrueFalseTotal
$read =~ /^(\d\d\d)-(.*)/ and do { $cont = 1; $code = $1; $msg .= $2 } 0 0 0
274 0 ▶ $read=~/^(\d\d\d)\s(.*)/ && do {$cont=0;$code=$1;$msg.=$2;};
Branch: 1 branch
BranchTrueFalseTotal
$read =~ /^(\d\d\d)\s(.*)/ and do { $cont = 0; $code = $1; $msg .= $2 } 0 0 0
275 0 ▶ print " ----> $read\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
276 } until ($cont==0);
277 };
278 0 $self->{'FTPCODE'}=$code;
279 0 $self->{'FTPMSG'}=$msg;
280 #$resp=~s/^\d\d\d\s/;
281 0 $self->{'FTPRAWMSG'}=$resp;
282  
283 0 ▶ if ($code>399) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code > 399) 0 0 0
284 #warn "Jaki¶ problem, chyba najlepiej sie wycofac\n";
285 #warn $resp;
286 # print STDERR "ERR: $resp\n";
287 #warn "Server said we're bad.";
288 0 $self->{'ErrMSG'}=$resp;
289 0 return undef;
290 };
291 0 ▶ print STDERR "RECV: ",$resp if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
292 0 return $msg;
293 }
294  
295 0 ▶sub list {return nlst(@_);};
Subroutine list: not called CC=1 SCAR=6.9
Pod undocumented
296 sub nlst {
297 0 ▶ my ($self,$mask)=@_;
Subroutine nlst: not called CC=13 SCAR=52.0
Pod undocumented
298 0 my $sock=$self->{'Sock'};
299 0 my $socket;
300 0 my (@files)=();
301 0 $socket=$self->datasocket();
302 0 ▶ if (defined($socket)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $socket) 0 0 0
303 0 my $response;
304 0 ▶ if (defined($mask)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mask) { } 0 0 0
305 0 $response=$self->command("NLST $mask");
306 } else {
307 0 $response=$self->command("NLST");
308 };
309 #print STDERR "ReSPONSE: -> : $response\n";
310 #print "KOD : ",$self->{'FTPCODE'},"\n";
311 # 1xx - cos jeszcze bedzie
312 # 2xx - to juz koniec
313 0 ▶ if ($response && ($self->{'FTPCODE'}<200) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response and $self->{"FTPCODE"} < 200) 0 0 0
Condition0%0/3
$response and $self->{"FTPCODE"} < 200
!ll&&!rl&&r
000
MC/DC0%0/2
$response and $self->{"FTPCODE"} < 200
$response $self->{"FTPCODE"} < 200
Truth table0%0/3
A and B
A= $responseB= $self->{"FTPCODE"} < 200
ABresult
0X0
100
111
314  
315 0 ▶ if ($self->{"EncryptData"}==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} == 1) 0 0 0
316 0 {my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;};
317 0 ▶ print STDERR "SSL for data connection enabled...\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
318 };
319 0 my $tmp;
320 0 ▶ while ($tmp=<$socket>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tmp = readline $socket)) 0 0 0
321 #print STDERR "G: $q";
322 #chop($tmp);chop($tmp);#\r\n -> remove.
323 0 $tmp=~s/\r\n$//;
324 0 push @files,$tmp;
325 };
326 };
327 0 close $socket;
328 0 ▶ if ($response && ($self->{'FTPCODE'}<200) ) {if ($response) {$response=$self->response();};}
Branch: 2 branches
BranchTrueFalseTotal
if ($response and $self->{"FTPCODE"} < 200) 0 0 0
if ($response) 0 0 0
Condition0%0/3
$response and $self->{"FTPCODE"} < 200
!ll&&!rl&&r
000
MC/DC0%0/2
$response and $self->{"FTPCODE"} < 200
$response $self->{"FTPCODE"} < 200
Truth table0%0/3
A and B
A= $responseB= $self->{"FTPCODE"} < 200
ABresult
0X0
100
111
329 0 ▶ print STDERR "resp(end LIST) ",$response if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
330 0 ▶ return \@files if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
331 };
332 0 return 0;
333 };
334  
335 sub putblat {
336 0 ▶ my ($putorblat,$stororappe,$self,$remote,$local)=@_;
Subroutine putblat: not called CC=17 SCAR=57.2
Pod undocumented
337 0 my $socket;
338 0 my $sock=$self->{'Sock'};
339 0 ▶ $local=$remote unless defined($local);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local 0 0 0
340 0 ▶ $self->command("TYPE I") unless ($self->{'DontDoType'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DontDoType"} 0 0 0
341 0 $socket=$self->datasocket();
342 0 ▶ die "SOCKET NOT CONNECTED! $!\n" unless defined($socket);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $socket 0 0 0
343 0 ▶ if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); };
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} != 0) 0 0 0
344 0 my $r=$self->command("$stororappe $remote");
345 0 ▶ if (!$r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
346 0 ▶ print STDERR "Problem trying to put file" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
347 0 return $r;
348 };
349  
350 0 ▶ if ($self->{"EncryptData"}==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} == 1) 0 0 0
351 0 {my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;};
352 0 ▶ print STDERR "SSL for data connection enabled...\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
353 };
354  
355 0 ▶ print STDERR "$stororappe connection opened.\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
356 0 select($socket);
357 #print "selected.\n";
358 0 ▶ if ($putorblat=~/put/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($putorblat =~ /put/) { } 0 0 0
359 0 ▶ CORE::open(L,"$local") or die "Can't open file $local, $!";
Branch: 1 branch
BranchTrueFalseTotal
CORE::open L, "$local" or die "Can't open file $local, $!" 0 0 0
360 0 binmode L;
361 0 my $tmp;
362 0 ▶ while ($tmp=<L>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tmp = readline L)) 0 0 0
363 0 print $tmp;
364 0 ▶ if (defined ($self->{'PutUpdateCallback'})) {$self->{'PutUpdateCallback'}->( length($tmp) ); };#TODO send sth..
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"PutUpdateCallback"}) 0 0 0
365 };#Probably syswrite/sysread would be smarter..
366 0 close L;
367 } else {
368 0 print $local;
369 0 ▶ if (defined ($self->{'PutUpdateCallback'})) {$self->{'PutUpdateCallback'}->( length($local) ); };#TODO send sth..
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"PutUpdateCallback"}) 0 0 0
370 }
371 #print "after write...\n";
372 0 select(STDOUT);
373 0 close $socket;
374 0 my $response=$self->response();
375 0 ▶ print STDERR "resp(after$stororappe) ",$response if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
376 0 ▶ if (defined $self->{'PutDoneCallBack'}) {$self->{'PutDoneCallBack'}->($response);};
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"PutDoneCallBack"}) 0 0 0
377 0 return $self->{'FTPRAWMSG'};
378 };
379 sub put {
380 0 ▶ putblat('put','STOR',@_);
Subroutine put: not called CC=1 SCAR=6.9
Pod undocumented
381 };
382 sub blat {
383 0 ▶ putblat('blat','STOR',@_);
Subroutine blat: not called CC=1 SCAR=6.9
Pod undocumented
384 };
385 sub appe {
386 0 ▶ putblat('put','APPE',@_);
Subroutine appe: not called CC=1 SCAR=6.9
Pod undocumented
387 };
388 sub blatappe {
389 0 ▶ putblat('blat','APPE',@_);
Subroutine blatappe: not called CC=1 SCAR=6.9
Pod undocumented
390 };
391  
392 sub get {
393 0 ▶ getslurp('get',@_);
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
394 };
395 sub slurp {
396 0 ▶ getslurp('slurp',@_);
Subroutine slurp: not called CC=1 SCAR=6.9
Pod undocumented
397 };
398  
399 sub getslurp {
400 0 ▶ my ($getorslurp,$self,$remote,$local)=@_;
Subroutine getslurp: not called CC=22 SCAR=61.3
Pod undocumented
401 0 my $socket;
402 0 my $sock=$self->{'Sock'};
403 0 ▶ $local=$remote unless defined($local);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local 0 0 0
404 0 $self->command("TYPE I");
405 0 $socket=$self->datasocket();
406 #tmp
407 1 ▶ use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
408 #setsockopt($sock,&SOL_SOCKET,&SO_KEEPALIVE,undef,undef) || warn "setsockopt: $!";
409 0 ▶ setsockopt($socket, SOL_SOCKET, SO_SNDTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $socket, 1, 21, "\17\0\0\0\0\0\0\0" or die 'setsockopt' . $! 0 0 0
410 0 ▶ setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $socket, 1, 20, "\17\0\0\0\0\0\0\0" or die 'setsockopt' . $! 0 0 0
411 0 ▶ setsockopt($socket, SOL_SOCKET, SO_KEEPALIVE, 1 ) or die "setsockopt".$!;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $socket, 1, 9, 1 or die 'setsockopt' . $! 0 0 0
412 0 setsockopt($sock, SOL_IP, IP_TOS(), pack("I*",0x08 ));#THROUGHPUT
413 #end tmp 2008-11-04
414  
415 0 ▶ if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); };
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} != 0) 0 0 0
416 0 my $r=$self->command("RETR $remote");
417 0 ▶ if (!$r) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r) 0 0 0
418 0 ▶ print STDERR "Problem trying to get file($remote)" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
419 0 return $r;
420 };
421  
422 0 ▶ if ($self->{"EncryptData"}==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} == 1) 0 0 0
423 0 {my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;};
424 0 ▶ print STDERR "SSL for data connection(RETR) enabled...\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
425 };
426 0 my $slurped="";
427 0 ▶ if ($getorslurp=~/get/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($getorslurp =~ /get/) { } 0 0 0
428 0 ▶ print STDERR "getorslurp: get\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
429 0 ▶ CORE::open(L,">$local") or die("Can't open file for writing $local, $!");
Branch: 1 branch
BranchTrueFalseTotal
CORE::open L, ">$local" or die "Can't open file for writing $local, $!" 0 0 0
430 0 binmode L;
431 # TODO replace while <$socket> with
432 # TODO while sysread($sock,$tmp,BUFSIZE);
433 0 my $tmp;
434 0 ▶ while (sysread($socket,$tmp,BUFSIZE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $socket, $tmp, 4096) 0 0 0
435 0 print L $tmp;
436 0 ▶ print STDERR length($tmp),":;\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
437 0 ▶ if (defined ($self->{'GetUpdateCallback'})) {$self->{'GetUpdateCallback'}->(length($tmp)); };#TODO send sth..
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"GetUpdateCallback"}) 0 0 0
438 };
439 #tmp-2008-10-22# while ($tmp=<$socket>) {
440 #tmp-2008-10-22# print L $tmp;
441 #tmp-2008-10-22# print STDERR length($tmp),":;\n" if $self->{Debug};
442 #tmp-2008-10-22# if (defined ($self->{'GetUpdateCallback'})) {$self->{'GetUpdateCallback'}->();print STDERR "GUC defined, and has been called\n"; };#TODO send sth..
443 #tmp-2008-10-22# };
444 0 close L;
445 } else {
446 0 ▶ print STDERR "getorslurp: slurp($getorslurp)\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
447 0 my $tmp;
448 0 ▶ while ($tmp=<$socket>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($tmp = readline $socket)) 0 0 0
449 0 ▶ $slurped.=$tmp;print STDERR ":." if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
450 0 ▶ if (defined ($self->{'GetUpdateCallback'})) {$self->{'GetUpdateCallback'}->( length($tmp) ); };#TODO send sth..
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"GetUpdateCallback"}) 0 0 0
451 };
452 };
453 0 close $socket;
454 0 my $response=$self->response();
455 0 ▶ print STDERR "resp(afterRETR) ",$response if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
456 0 ▶ if (defined $self->{'GetDoneCallBack'}) {$self->{'GetDoneCallBack'}->($response);};
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"GetDoneCallBack"}) 0 0 0
457 0 return $slurped;
458 };
459  
460 sub datasocket {
461 0 ▶ my ($self)=@_;
Subroutine datasocket: not called CC=6 SCAR=37.4
Pod undocumented
462 0 my ($tmp,$socket);
463 0 ▶ if ($tmp=$self->command("PASV")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp = $self->command('PASV')) { } 0 0 0
464 0 ▶ if ($self->msgcode()==227 && $tmp=~/[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->msgcode == 227 and $tmp =~ /[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) { } 0 0 0
Condition0%0/3
$self->msgcode == 227 and $tmp =~ /[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->msgcode == 227 and $tmp =~ /[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/
$self->msgcode == 227 $tmp =~ /[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/
Truth table0%0/3
A and B
A= $self->msgcode == 227B= $tmp =~ /[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/
ABresult
0X0
100
111
465 0 my $port=$5*256+$6;
466 0 my $host="$1.$2.$3.$4";
467 0 $socket = Net::SSLeay::Handle->make_socket($host, $port);
468 0 ▶ if (defined($socket)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $socket) { } 0 0 0
469 0 ▶ print STDERR "Data link connected.. to $host at $port\n" if $self->{Debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Debug"} 0 0 0
470 } else {
471 0 warn "Data link NOT connected ($host,$port) $!";
472 0 die "Data link NOT connected ($host,$port) $!";
473 };
474 } else {
475 0 die "Problem parsing PASV response($tmp)";
476 };
477 } else {
478 0 warn "undefined response to PASV cmd (err:$!) {H: ".$self->{'Host'}." P:".$self->{'Port'}."}\n";# unless defined($read);
479 0 die "Problem sending PASV request, $tmp";
480 };# end if self -> command PASV
481 0 return $socket
482 };
483  
484 sub trivialm {
485 1 ▶ my ($self)=@_;
Subroutine trivialm: called CC=1 SCAR=0.0
Pod undocumented
486 1 return 1;
487 };
488  
489 # extras...
490 #
491 sub registerGetUpdateCallback {
492 0 ▶ my ($self,$callback_ref)=@_;
Subroutine registerGetUpdateCallback: not called CC=1 SCAR=6.9
Pod undocumented
493  
494 0 $self->{'GetUpdateCallback'} = $callback_ref;
495 }
496 sub registerGetDoneCallback {
497 0 ▶ my ($self,$callback_ref)=@_;
Subroutine registerGetDoneCallback: not called CC=1 SCAR=6.9
Pod undocumented
498  
499 0 $self->{'GetDoneCallback'} = $callback_ref;
500 }
501 sub registerPutUpdateCallback {
502 0 ▶ my ($self,$callback_ref)=@_;
Subroutine registerPutUpdateCallback: not called CC=1 SCAR=6.9
Pod undocumented
503  
504 0 $self->{'PutUpdateCallback'} = $callback_ref;
505 }
506 sub registerPutDoneCallback {
507 0 ▶ my ($self,$callback_ref)=@_;
Subroutine registerPutDoneCallback: not called CC=1 SCAR=6.9
Pod undocumented
508  
509 0 $self->{'PutDoneCallback'} = $callback_ref;
510 }
511  
512 sub setup_protection {
513 0 ▶ my ($self)=@_;
Subroutine setup_protection: not called CC=3 SCAR=24.8
Pod undocumented
514 0 ▶ if ($self->{'Encrypt'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'Encrypt'}) { } 0 0 0
515 0 $self->command("PBSZ 0");# TODO
516 0 ▶ if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); };
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EncryptData"} != 0) 0 0 0
517 0 } else {return 1;};
518 };
519  
520  
521  
522 1 1;
523 __END__
↑ Summary example.pl »