| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Lite::FTP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
24330
|
use 5.006000; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
24
|
|
|
|
1
|
|
|
|
|
40
|
|
|
7
|
1
|
|
|
1
|
|
1020
|
use IO::Handle; |
|
|
1
|
|
|
|
|
8328
|
|
|
|
1
|
|
|
|
|
69
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
|
10
|
1
|
|
|
1
|
|
1029
|
use AutoLoader qw(AUTOLOAD); |
|
|
1
|
|
|
|
|
1836
|
|
|
|
1
|
|
|
|
|
7
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
) ] ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.61'; |
|
31
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
32
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
|
33
|
1
|
|
|
1
|
|
115
|
use constant BUFSIZE => 4096; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
90
|
|
|
34
|
1
|
|
|
1
|
|
962
|
BEGIN { |
|
35
|
1
|
|
|
1
|
|
884
|
use Net::SSLeay::Handle qw/shutdown/; |
|
|
1
|
|
|
|
|
21130
|
|
|
|
1
|
|
|
|
|
59
|
|
|
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
|
|
|
1
|
0
|
13
|
my $class=shift; |
|
44
|
1
|
|
|
|
|
3
|
my $self={}; |
|
45
|
1
|
|
|
|
|
3
|
bless $self,$class; |
|
46
|
|
|
|
|
|
|
# $self->{'DBHandle'}=$dbh; |
|
47
|
1
|
|
|
|
|
13
|
$self->{"CreationTime"}=time; |
|
48
|
1
|
|
|
|
|
3
|
$self->{"Connected"}=0; |
|
49
|
1
|
|
|
|
|
2
|
$self->{"EncryptData"}=1; |
|
50
|
1
|
|
|
|
|
3
|
$self->{"Encrypt"}=1; |
|
51
|
1
|
|
|
|
|
2
|
$self->{"Debug"}=0; |
|
52
|
1
|
|
|
|
|
4
|
$self->{"ErrMSG"}=undef; |
|
53
|
1
|
|
|
|
|
1
|
$self->{"GetUpdateCallback"} = undef; |
|
54
|
1
|
|
|
|
|
3
|
$self->{"GetDoneCallback"} = undef; |
|
55
|
1
|
|
|
|
|
3
|
$self->{"PutUpdateCallback"} = undef; |
|
56
|
1
|
|
|
|
|
3
|
$self->{"PutDoneCallback"} = undef; |
|
57
|
1
|
|
|
|
|
4
|
return $self; |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub user($$) { |
|
61
|
0
|
|
|
0
|
0
|
0
|
my ($self,$user)=@_; |
|
62
|
0
|
|
|
|
|
0
|
$self->command("USER $user"); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
sub pass($$) { |
|
65
|
0
|
|
|
0
|
0
|
0
|
my ($self,$pass)=@_; |
|
66
|
0
|
|
|
|
|
0
|
$self->command("PASS $pass"); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
sub login($$$) { |
|
69
|
0
|
|
|
0
|
0
|
0
|
my ($self,$user,$pass)=@_; |
|
70
|
0
|
|
|
|
|
0
|
$self->command("USER $user"); |
|
71
|
0
|
|
|
|
|
0
|
$self->command("PASS $pass"); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub cwd ($$) { |
|
75
|
0
|
|
|
0
|
0
|
0
|
my ($self,$data)=@_; |
|
76
|
0
|
|
|
|
|
0
|
$self->command("CWD $data"); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
sub mkdir ($$) { |
|
79
|
0
|
|
|
0
|
0
|
0
|
my ($self,$data)=@_; |
|
80
|
0
|
|
|
|
|
0
|
$self->command("MKD $data"); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
sub rmdir ($$) { |
|
83
|
0
|
|
|
0
|
0
|
0
|
my ($self,$data)=@_; |
|
84
|
0
|
|
|
|
|
0
|
$self->command("RMD $data"); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub size ($$) { |
|
88
|
0
|
|
|
0
|
0
|
0
|
my ($self,$filename)=@_; |
|
89
|
0
|
0
|
|
|
|
0
|
my $size=$self->command("SIZE $filename");chop $size if defined($size); |
|
|
0
|
|
|
|
|
0
|
|
|
90
|
0
|
|
|
|
|
0
|
return $size; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
sub cdup ($$) { |
|
93
|
0
|
|
|
0
|
0
|
0
|
my ($self,$data)=@_; |
|
94
|
0
|
|
|
|
|
0
|
$self->command("CDUP"); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub dele { |
|
97
|
0
|
|
|
0
|
0
|
0
|
my ($self,$pathname)=@_; |
|
98
|
0
|
0
|
|
|
|
0
|
return undef unless defined($pathname); |
|
99
|
0
|
|
|
|
|
0
|
$self->command("DELE $pathname"); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
0
|
|
|
0
|
0
|
0
|
sub rm {dele(@_);}; |
|
102
|
0
|
|
|
0
|
0
|
0
|
sub delete {dele(@_);}; |
|
103
|
0
|
|
|
0
|
0
|
0
|
sub del { shift->del(@_) }; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub rawmessage ($) { |
|
106
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
107
|
0
|
|
|
|
|
0
|
return $self->{'FTPRAWMSG'}; |
|
108
|
|
|
|
|
|
|
}; |
|
109
|
|
|
|
|
|
|
sub message ($) { |
|
110
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
111
|
0
|
|
|
|
|
0
|
return $self->{'FTPMSG'}; |
|
112
|
|
|
|
|
|
|
}; |
|
113
|
|
|
|
|
|
|
sub msgcode ($) { |
|
114
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
115
|
0
|
|
|
|
|
0
|
return $self->{'FTPCODE'}; |
|
116
|
|
|
|
|
|
|
}; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub readln { |
|
119
|
0
|
|
|
0
|
0
|
0
|
my ($sock)=@_; |
|
120
|
0
|
|
|
|
|
0
|
my ($data,$ln); |
|
121
|
0
|
0
|
|
|
|
0
|
if (sysread($sock,$data,BUFSIZE)) { |
|
122
|
0
|
|
|
|
|
0
|
$ln=$data; |
|
123
|
0
|
|
|
|
|
0
|
while ($data!~/\n/) { |
|
124
|
0
|
0
|
|
|
|
0
|
if (sysread($sock,$data,BUFSIZE)) { |
|
125
|
|
|
|
|
|
|
#print "OPEN..Received: {$data}\n";# if $self->{Debug}; |
|
126
|
0
|
|
|
|
|
0
|
$ln.=$data; |
|
127
|
|
|
|
|
|
|
}; |
|
128
|
|
|
|
|
|
|
}; |
|
129
|
|
|
|
|
|
|
}; |
|
130
|
0
|
|
|
|
|
0
|
return $ln; |
|
131
|
|
|
|
|
|
|
}; |
|
132
|
|
|
|
|
|
|
|
|
133
|
0
|
|
|
0
|
0
|
0
|
sub SOL_IP { 0; }; |
|
134
|
|
|
|
|
|
|
sub IP_TOS { 1; }; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub open($$$) { |
|
137
|
0
|
|
|
0
|
0
|
0
|
my ($self,$host,$port)=@_; |
|
138
|
0
|
|
|
|
|
0
|
my ($data); |
|
139
|
|
|
|
|
|
|
my $sock; |
|
140
|
0
|
|
|
|
|
0
|
$sock = Net::SSLeay::Handle->make_socket($host, $port); |
|
141
|
0
|
|
|
|
|
0
|
$self->{'Sock'}=$sock; |
|
142
|
0
|
|
|
|
|
0
|
$self->{'Host'}=$host; |
|
143
|
0
|
|
|
|
|
0
|
$self->{'Port'}=$port; |
|
144
|
|
|
|
|
|
|
#tmp |
|
145
|
1
|
|
|
1
|
|
12
|
use Socket; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3490
|
|
|
146
|
|
|
|
|
|
|
#setsockopt($sock,&SOL_SOCKET,&SO_KEEPALIVE,undef,undef) || warn "setsockopt: $!"; |
|
147
|
0
|
0
|
|
|
|
0
|
setsockopt($sock, SOL_SOCKET, SO_SNDTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!; |
|
148
|
0
|
0
|
|
|
|
0
|
setsockopt($sock, SOL_SOCKET, SO_RCVTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!; |
|
149
|
0
|
0
|
|
|
|
0
|
setsockopt($sock, SOL_SOCKET, SO_KEEPALIVE, 1 ) or die "setsockopt".$!; |
|
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
|
|
|
|
|
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
|
0
|
|
|
|
0
|
if ($self->{'FTPS'}) { |
|
162
|
|
|
|
|
|
|
#{tie(*S, "Net::SSLeay::Handle", $sock);$sock = \*S;}; |
|
163
|
|
|
|
|
|
|
# Unique glob? |
|
164
|
0
|
|
|
|
|
0
|
{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $sock);$sock = \*$io;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
0
|
if ($data=readln($sock)) { |
|
170
|
0
|
0
|
|
|
|
0
|
print STDERR "OPEN.Received: $data" if $self->{Debug}; |
|
171
|
0
|
|
|
|
|
0
|
$data=$self->responserest($data); |
|
172
|
0
|
0
|
|
|
|
0
|
print STDERR "OPEN..Received: $data" if $self->{Debug}; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
0
|
0
|
|
|
0
|
if ($self->{'Encrypt'} && (! $self->{'FTPS'} )) { |
|
176
|
0
|
|
|
|
|
0
|
$data="AUTH TLS\r\n"; |
|
177
|
0
|
|
|
|
|
0
|
syswrite($sock,$data); |
|
178
|
0
|
0
|
|
|
|
0
|
if ($data=readln($sock)) { |
|
179
|
0
|
0
|
|
|
|
0
|
print STDERR "Received: $data" if $self->{Debug}; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
0
|
|
|
|
|
0
|
$self->{'RAWSock'}=$sock; |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
0
|
0
|
|
|
0
|
if ($self->{'Encrypt'} && (! $self->{'FTPS'} )) { |
|
185
|
|
|
|
|
|
|
#{tie(*S, "Net::SSLeay::Handle", $sock);$sock = \*S;}; |
|
186
|
|
|
|
|
|
|
# Unique glob? |
|
187
|
0
|
|
|
|
|
0
|
{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $sock);$sock = \*$io;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
0
|
$self->{'Sock'}=$sock; |
|
191
|
0
|
|
|
|
|
0
|
{select($sock);$|=1;select(STDOUT);};#unbuffer socket |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
192
|
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
0
|
$self->setup_protection(); |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# |
|
196
|
0
|
|
|
|
|
0
|
return 1; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub quit { |
|
200
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
201
|
0
|
|
|
|
|
0
|
return $self->command("QUIT"); |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
sub noop { |
|
204
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
205
|
0
|
|
|
|
|
0
|
return $self->command("NOOP"); |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
sub rename ($$$) { |
|
208
|
0
|
|
|
0
|
0
|
0
|
my ($self,$from,$to)=@_; |
|
209
|
|
|
|
|
|
|
#"RNFR plik1" |
|
210
|
|
|
|
|
|
|
#"RNTO plik2" |
|
211
|
0
|
0
|
|
|
|
0
|
if ($self->command("RNFR $from")) { |
|
|
0
|
|
|
|
|
0
|
|
|
212
|
0
|
|
|
|
|
0
|
return $self->command("RNTO $to"); |
|
213
|
|
|
|
|
|
|
} else {return 0;}; |
|
214
|
|
|
|
|
|
|
}; |
|
215
|
|
|
|
|
|
|
sub mdtm ($$) { |
|
216
|
0
|
|
|
0
|
0
|
0
|
my ($self,$file)=@_; |
|
217
|
0
|
|
|
|
|
0
|
return $self->command("MDTM $file"); |
|
218
|
|
|
|
|
|
|
}; |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub command ($$){ |
|
221
|
0
|
|
|
0
|
0
|
0
|
my ($self,$data)=@_; |
|
222
|
0
|
0
|
|
|
|
0
|
print STDERR "Sending: ",$data."\n" if $self->{Debug}; |
|
223
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
224
|
0
|
|
|
|
|
0
|
print $sock $data."\r\n"; |
|
225
|
0
|
|
|
|
|
0
|
return $self->response(); |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub response ($) { |
|
229
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
230
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
231
|
0
|
|
|
|
|
0
|
my ($read,$resp,$code,$cont); |
|
232
|
0
|
|
|
|
|
0
|
$read=($resp=<$sock>); |
|
233
|
0
|
0
|
|
|
|
0
|
if (!defined($read)) { |
|
234
|
0
|
|
|
|
|
0
|
warn "Damn! undefined response (err:$!) {H: ".$self->{'Host'}." P:".$self->{'Port'}."}\n";# unless defined($read); |
|
235
|
0
|
|
|
|
|
0
|
$self->{'FTPCODE'}=undef; |
|
236
|
0
|
|
|
|
|
0
|
$self->{'FTPMSG'}=undef; |
|
237
|
0
|
|
|
|
|
0
|
$self->{'FTPRAWMSG'}=undef; |
|
238
|
0
|
|
|
|
|
0
|
return undef;# unless defined($read); |
|
239
|
|
|
|
|
|
|
}; |
|
240
|
0
|
|
|
|
|
0
|
return $self->responserest($read); |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub responserest ($$) { |
|
244
|
0
|
|
|
0
|
0
|
0
|
my ($self,$read)=@_; |
|
245
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
246
|
0
|
|
|
|
|
0
|
my ($resp,$code,$cont,$msg); |
|
247
|
0
|
|
|
|
|
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
|
0
|
|
|
|
0
|
print STDERR "SRV Response: $read" if $self->{Debug}; |
|
261
|
0
|
0
|
|
|
|
0
|
$read=~/^(\d\d\d)\s(.*)/ && do { |
|
262
|
0
|
|
|
|
|
0
|
$code=$1;$msg=$2;chomp($msg); |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
263
|
|
|
|
|
|
|
}; |
|
264
|
0
|
0
|
|
|
|
0
|
$read=~/^(\d\d\d)-(.*)/ && do { |
|
265
|
0
|
|
|
|
|
0
|
$cont=1;$code=$1;$msg.=$2; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
266
|
0
|
0
|
|
|
|
0
|
print STDERR "wielolinijkowa odpowiedz z servera.." if $self->{Debug}; |
|
267
|
|
|
|
|
|
|
}; |
|
268
|
0
|
0
|
|
|
|
0
|
if ($read=~/^(\d\d\d)\s(.*)/m) {$cont=0;}; # wyjatek na wielolinijkowe na dziendobry |
|
|
0
|
|
|
|
|
0
|
|
|
269
|
0
|
0
|
|
|
|
0
|
if ($cont) { |
|
270
|
0
|
|
|
|
|
0
|
do { |
|
271
|
0
|
|
|
|
|
0
|
$read=<$sock>; |
|
272
|
0
|
|
|
|
|
0
|
$resp.=$read; |
|
273
|
0
|
0
|
|
|
|
0
|
$read=~/^(\d\d\d)-(.*)/ && do {$cont=1;$code=$1;$msg.=$2;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
274
|
0
|
0
|
|
|
|
0
|
$read=~/^(\d\d\d)\s(.*)/ && do {$cont=0;$code=$1;$msg.=$2;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
275
|
0
|
0
|
|
|
|
0
|
print " ----> $read\n" if $self->{Debug}; |
|
276
|
|
|
|
|
|
|
} until ($cont==0); |
|
277
|
|
|
|
|
|
|
}; |
|
278
|
0
|
|
|
|
|
0
|
$self->{'FTPCODE'}=$code; |
|
279
|
0
|
|
|
|
|
0
|
$self->{'FTPMSG'}=$msg; |
|
280
|
|
|
|
|
|
|
#$resp=~s/^\d\d\d\s/; |
|
281
|
0
|
|
|
|
|
0
|
$self->{'FTPRAWMSG'}=$resp; |
|
282
|
|
|
|
|
|
|
|
|
283
|
0
|
0
|
|
|
|
0
|
if ($code>399) { |
|
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
|
|
|
|
|
0
|
$self->{'ErrMSG'}=$resp; |
|
289
|
0
|
|
|
|
|
0
|
return undef; |
|
290
|
|
|
|
|
|
|
}; |
|
291
|
0
|
0
|
|
|
|
0
|
print STDERR "RECV: ",$resp if $self->{Debug}; |
|
292
|
0
|
|
|
|
|
0
|
return $msg; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
0
|
|
|
0
|
0
|
0
|
sub list {return nlst(@_);}; |
|
296
|
|
|
|
|
|
|
sub nlst { |
|
297
|
0
|
|
|
0
|
0
|
0
|
my ($self,$mask)=@_; |
|
298
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
299
|
0
|
|
|
|
|
0
|
my $socket; |
|
300
|
0
|
|
|
|
|
0
|
my (@files)=(); |
|
301
|
0
|
|
|
|
|
0
|
$socket=$self->datasocket(); |
|
302
|
0
|
0
|
|
|
|
0
|
if (defined($socket)) { |
|
303
|
0
|
|
|
|
|
0
|
my $response; |
|
304
|
0
|
0
|
|
|
|
0
|
if (defined($mask)) { |
|
305
|
0
|
|
|
|
|
0
|
$response=$self->command("NLST $mask"); |
|
306
|
|
|
|
|
|
|
} else { |
|
307
|
0
|
|
|
|
|
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
|
0
|
0
|
|
|
0
|
if ($response && ($self->{'FTPCODE'}<200) ) { |
|
314
|
|
|
|
|
|
|
|
|
315
|
0
|
0
|
|
|
|
0
|
if ($self->{"EncryptData"}==1) { |
|
316
|
0
|
|
|
|
|
0
|
{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
317
|
0
|
0
|
|
|
|
0
|
print STDERR "SSL for data connection enabled...\n" if $self->{Debug}; |
|
318
|
|
|
|
|
|
|
}; |
|
319
|
0
|
|
|
|
|
0
|
my $tmp; |
|
320
|
0
|
|
|
|
|
0
|
while ($tmp=<$socket>) { |
|
321
|
|
|
|
|
|
|
#print STDERR "G: $q"; |
|
322
|
|
|
|
|
|
|
#chop($tmp);chop($tmp);#\r\n -> remove. |
|
323
|
0
|
|
|
|
|
0
|
$tmp=~s/\r\n$//; |
|
324
|
0
|
|
|
|
|
0
|
push @files,$tmp; |
|
325
|
|
|
|
|
|
|
}; |
|
326
|
|
|
|
|
|
|
}; |
|
327
|
0
|
|
|
|
|
0
|
close $socket; |
|
328
|
0
|
0
|
0
|
|
|
0
|
if ($response && ($self->{'FTPCODE'}<200) ) {if ($response) {$response=$self->response();};} |
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
329
|
0
|
0
|
|
|
|
0
|
print STDERR "resp(end LIST) ",$response if $self->{Debug}; |
|
330
|
0
|
0
|
|
|
|
0
|
return \@files if $response; |
|
331
|
|
|
|
|
|
|
}; |
|
332
|
0
|
|
|
|
|
0
|
return 0; |
|
333
|
|
|
|
|
|
|
}; |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub putblat { |
|
336
|
0
|
|
|
0
|
0
|
0
|
my ($putorblat,$stororappe,$self,$remote,$local)=@_; |
|
337
|
0
|
|
|
|
|
0
|
my $socket; |
|
338
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
339
|
0
|
0
|
|
|
|
0
|
$local=$remote unless defined($local); |
|
340
|
0
|
0
|
|
|
|
0
|
$self->command("TYPE I") unless ($self->{'DontDoType'}); |
|
341
|
0
|
|
|
|
|
0
|
$socket=$self->datasocket(); |
|
342
|
0
|
0
|
|
|
|
0
|
die "SOCKET NOT CONNECTED! $!\n" unless defined($socket); |
|
343
|
0
|
0
|
|
|
|
0
|
if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); }; |
|
|
0
|
|
|
|
|
0
|
|
|
344
|
0
|
|
|
|
|
0
|
my $r=$self->command("$stororappe $remote"); |
|
345
|
0
|
0
|
|
|
|
0
|
if (!$r) { |
|
346
|
0
|
0
|
|
|
|
0
|
print STDERR "Problem trying to put file" if $self->{Debug}; |
|
347
|
0
|
|
|
|
|
0
|
return $r; |
|
348
|
|
|
|
|
|
|
}; |
|
349
|
|
|
|
|
|
|
|
|
350
|
0
|
0
|
|
|
|
0
|
if ($self->{"EncryptData"}==1) { |
|
351
|
0
|
|
|
|
|
0
|
{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
352
|
0
|
0
|
|
|
|
0
|
print STDERR "SSL for data connection enabled...\n" if $self->{Debug}; |
|
353
|
|
|
|
|
|
|
}; |
|
354
|
|
|
|
|
|
|
|
|
355
|
0
|
0
|
|
|
|
0
|
print STDERR "$stororappe connection opened.\n" if $self->{Debug}; |
|
356
|
0
|
|
|
|
|
0
|
select($socket); |
|
357
|
|
|
|
|
|
|
#print "selected.\n"; |
|
358
|
0
|
0
|
|
|
|
0
|
if ($putorblat=~/put/) { |
|
359
|
0
|
0
|
|
|
|
0
|
CORE::open(L,"$local") or die "Can't open file $local, $!"; |
|
360
|
0
|
|
|
|
|
0
|
binmode L; |
|
361
|
0
|
|
|
|
|
0
|
my $tmp; |
|
362
|
0
|
|
|
|
|
0
|
while ($tmp=) { |
|
363
|
0
|
|
|
|
|
0
|
print $tmp; |
|
364
|
0
|
0
|
|
|
|
0
|
if (defined ($self->{'PutUpdateCallback'})) {$self->{'PutUpdateCallback'}->( length($tmp) ); };#TODO send sth.. |
|
|
0
|
|
|
|
|
0
|
|
|
365
|
|
|
|
|
|
|
};#Probably syswrite/sysread would be smarter.. |
|
366
|
0
|
|
|
|
|
0
|
close L; |
|
367
|
|
|
|
|
|
|
} else { |
|
368
|
0
|
|
|
|
|
0
|
print $local; |
|
369
|
0
|
0
|
|
|
|
0
|
if (defined ($self->{'PutUpdateCallback'})) {$self->{'PutUpdateCallback'}->( length($local) ); };#TODO send sth.. |
|
|
0
|
|
|
|
|
0
|
|
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
#print "after write...\n"; |
|
372
|
0
|
|
|
|
|
0
|
select(STDOUT); |
|
373
|
0
|
|
|
|
|
0
|
close $socket; |
|
374
|
0
|
|
|
|
|
0
|
my $response=$self->response(); |
|
375
|
0
|
0
|
|
|
|
0
|
print STDERR "resp(after$stororappe) ",$response if $self->{Debug}; |
|
376
|
0
|
0
|
|
|
|
0
|
if (defined $self->{'PutDoneCallBack'}) {$self->{'PutDoneCallBack'}->($response);}; |
|
|
0
|
|
|
|
|
0
|
|
|
377
|
0
|
|
|
|
|
0
|
return $self->{'FTPRAWMSG'}; |
|
378
|
|
|
|
|
|
|
}; |
|
379
|
|
|
|
|
|
|
sub put { |
|
380
|
0
|
|
|
0
|
0
|
0
|
putblat('put','STOR',@_); |
|
381
|
|
|
|
|
|
|
}; |
|
382
|
|
|
|
|
|
|
sub blat { |
|
383
|
0
|
|
|
0
|
0
|
0
|
putblat('blat','STOR',@_); |
|
384
|
|
|
|
|
|
|
}; |
|
385
|
|
|
|
|
|
|
sub appe { |
|
386
|
0
|
|
|
0
|
0
|
0
|
putblat('put','APPE',@_); |
|
387
|
|
|
|
|
|
|
}; |
|
388
|
|
|
|
|
|
|
sub blatappe { |
|
389
|
0
|
|
|
0
|
0
|
0
|
putblat('blat','APPE',@_); |
|
390
|
|
|
|
|
|
|
}; |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub get { |
|
393
|
0
|
|
|
0
|
0
|
0
|
getslurp('get',@_); |
|
394
|
|
|
|
|
|
|
}; |
|
395
|
|
|
|
|
|
|
sub slurp { |
|
396
|
0
|
|
|
0
|
0
|
0
|
getslurp('slurp',@_); |
|
397
|
|
|
|
|
|
|
}; |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub getslurp { |
|
400
|
0
|
|
|
0
|
0
|
0
|
my ($getorslurp,$self,$remote,$local)=@_; |
|
401
|
0
|
|
|
|
|
0
|
my $socket; |
|
402
|
0
|
|
|
|
|
0
|
my $sock=$self->{'Sock'}; |
|
403
|
0
|
0
|
|
|
|
0
|
$local=$remote unless defined($local); |
|
404
|
0
|
|
|
|
|
0
|
$self->command("TYPE I"); |
|
405
|
0
|
|
|
|
|
0
|
$socket=$self->datasocket(); |
|
406
|
|
|
|
|
|
|
#tmp |
|
407
|
1
|
|
|
1
|
|
9
|
use Socket; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2334
|
|
|
408
|
|
|
|
|
|
|
#setsockopt($sock,&SOL_SOCKET,&SO_KEEPALIVE,undef,undef) || warn "setsockopt: $!"; |
|
409
|
0
|
0
|
|
|
|
0
|
setsockopt($socket, SOL_SOCKET, SO_SNDTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!; |
|
410
|
0
|
0
|
|
|
|
0
|
setsockopt($socket, SOL_SOCKET, SO_RCVTIMEO, pack('LL', 15, 0) ) or die "setsockopt".$!; |
|
411
|
0
|
0
|
|
|
|
0
|
setsockopt($socket, SOL_SOCKET, SO_KEEPALIVE, 1 ) or die "setsockopt".$!; |
|
412
|
0
|
|
|
|
|
0
|
setsockopt($sock, SOL_IP, IP_TOS(), pack("I*",0x08 ));#THROUGHPUT |
|
413
|
|
|
|
|
|
|
#end tmp 2008-11-04 |
|
414
|
|
|
|
|
|
|
|
|
415
|
0
|
0
|
|
|
|
0
|
if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); }; |
|
|
0
|
|
|
|
|
0
|
|
|
416
|
0
|
|
|
|
|
0
|
my $r=$self->command("RETR $remote"); |
|
417
|
0
|
0
|
|
|
|
0
|
if (!$r) { |
|
418
|
0
|
0
|
|
|
|
0
|
print STDERR "Problem trying to get file($remote)" if $self->{Debug}; |
|
419
|
0
|
|
|
|
|
0
|
return $r; |
|
420
|
|
|
|
|
|
|
}; |
|
421
|
|
|
|
|
|
|
|
|
422
|
0
|
0
|
|
|
|
0
|
if ($self->{"EncryptData"}==1) { |
|
423
|
0
|
|
|
|
|
0
|
{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$socket = \*$io;}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
424
|
0
|
0
|
|
|
|
0
|
print STDERR "SSL for data connection(RETR) enabled...\n" if $self->{Debug}; |
|
425
|
|
|
|
|
|
|
}; |
|
426
|
0
|
|
|
|
|
0
|
my $slurped=""; |
|
427
|
0
|
0
|
|
|
|
0
|
if ($getorslurp=~/get/) { |
|
428
|
0
|
0
|
|
|
|
0
|
print STDERR "getorslurp: get\n" if $self->{Debug}; |
|
429
|
0
|
0
|
|
|
|
0
|
CORE::open(L,">$local") or die("Can't open file for writing $local, $!"); |
|
430
|
0
|
|
|
|
|
0
|
binmode L; |
|
431
|
|
|
|
|
|
|
# TODO replace while <$socket> with |
|
432
|
|
|
|
|
|
|
# TODO while sysread($sock,$tmp,BUFSIZE); |
|
433
|
0
|
|
|
|
|
0
|
my $tmp; |
|
434
|
0
|
|
|
|
|
0
|
while (sysread($socket,$tmp,BUFSIZE)) { |
|
435
|
0
|
|
|
|
|
0
|
print L $tmp; |
|
436
|
0
|
0
|
|
|
|
0
|
print STDERR length($tmp),":;\n" if $self->{Debug}; |
|
437
|
0
|
0
|
|
|
|
0
|
if (defined ($self->{'GetUpdateCallback'})) {$self->{'GetUpdateCallback'}->(length($tmp)); };#TODO send sth.. |
|
|
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
|
|
|
|
|
0
|
close L; |
|
445
|
|
|
|
|
|
|
} else { |
|
446
|
0
|
0
|
|
|
|
0
|
print STDERR "getorslurp: slurp($getorslurp)\n" if $self->{Debug}; |
|
447
|
0
|
|
|
|
|
0
|
my $tmp; |
|
448
|
0
|
|
|
|
|
0
|
while ($tmp=<$socket>) { |
|
449
|
0
|
0
|
|
|
|
0
|
$slurped.=$tmp;print STDERR ":." if $self->{Debug}; |
|
|
0
|
|
|
|
|
0
|
|
|
450
|
0
|
0
|
|
|
|
0
|
if (defined ($self->{'GetUpdateCallback'})) {$self->{'GetUpdateCallback'}->( length($tmp) ); };#TODO send sth.. |
|
|
0
|
|
|
|
|
0
|
|
|
451
|
|
|
|
|
|
|
}; |
|
452
|
|
|
|
|
|
|
}; |
|
453
|
0
|
|
|
|
|
0
|
close $socket; |
|
454
|
0
|
|
|
|
|
0
|
my $response=$self->response(); |
|
455
|
0
|
0
|
|
|
|
0
|
print STDERR "resp(afterRETR) ",$response if $self->{Debug}; |
|
456
|
0
|
0
|
|
|
|
0
|
if (defined $self->{'GetDoneCallBack'}) {$self->{'GetDoneCallBack'}->($response);}; |
|
|
0
|
|
|
|
|
0
|
|
|
457
|
0
|
|
|
|
|
0
|
return $slurped; |
|
458
|
|
|
|
|
|
|
}; |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
sub datasocket { |
|
461
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
|
462
|
0
|
|
|
|
|
0
|
my ($tmp,$socket); |
|
463
|
0
|
0
|
|
|
|
0
|
if ($tmp=$self->command("PASV")) { |
|
464
|
0
|
0
|
0
|
|
|
0
|
if ($self->msgcode()==227 && $tmp=~/[^\d]*(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)/) { |
|
465
|
0
|
|
|
|
|
0
|
my $port=$5*256+$6; |
|
466
|
0
|
|
|
|
|
0
|
my $host="$1.$2.$3.$4"; |
|
467
|
0
|
|
|
|
|
0
|
$socket = Net::SSLeay::Handle->make_socket($host, $port); |
|
468
|
0
|
0
|
|
|
|
0
|
if (defined($socket)) { |
|
469
|
0
|
0
|
|
|
|
0
|
print STDERR "Data link connected.. to $host at $port\n" if $self->{Debug}; |
|
470
|
|
|
|
|
|
|
} else { |
|
471
|
0
|
|
|
|
|
0
|
warn "Data link NOT connected ($host,$port) $!"; |
|
472
|
0
|
|
|
|
|
0
|
die "Data link NOT connected ($host,$port) $!"; |
|
473
|
|
|
|
|
|
|
}; |
|
474
|
|
|
|
|
|
|
} else { |
|
475
|
0
|
|
|
|
|
0
|
die "Problem parsing PASV response($tmp)"; |
|
476
|
|
|
|
|
|
|
}; |
|
477
|
|
|
|
|
|
|
} else { |
|
478
|
0
|
|
|
|
|
0
|
warn "undefined response to PASV cmd (err:$!) {H: ".$self->{'Host'}." P:".$self->{'Port'}."}\n";# unless defined($read); |
|
479
|
0
|
|
|
|
|
0
|
die "Problem sending PASV request, $tmp"; |
|
480
|
|
|
|
|
|
|
};# end if self -> command PASV |
|
481
|
0
|
|
|
|
|
0
|
return $socket |
|
482
|
|
|
|
|
|
|
}; |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
sub trivialm { |
|
485
|
1
|
|
|
1
|
0
|
417
|
my ($self)=@_; |
|
486
|
1
|
|
|
|
|
6
|
return 1; |
|
487
|
|
|
|
|
|
|
}; |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# extras... |
|
490
|
|
|
|
|
|
|
# |
|
491
|
|
|
|
|
|
|
sub registerGetUpdateCallback { |
|
492
|
0
|
|
|
0
|
0
|
|
my ($self,$callback_ref)=@_; |
|
493
|
|
|
|
|
|
|
|
|
494
|
0
|
|
|
|
|
|
$self->{'GetUpdateCallback'} = $callback_ref; |
|
495
|
|
|
|
|
|
|
} |
|
496
|
|
|
|
|
|
|
sub registerGetDoneCallback { |
|
497
|
0
|
|
|
0
|
0
|
|
my ($self,$callback_ref)=@_; |
|
498
|
|
|
|
|
|
|
|
|
499
|
0
|
|
|
|
|
|
$self->{'GetDoneCallback'} = $callback_ref; |
|
500
|
|
|
|
|
|
|
} |
|
501
|
|
|
|
|
|
|
sub registerPutUpdateCallback { |
|
502
|
0
|
|
|
0
|
0
|
|
my ($self,$callback_ref)=@_; |
|
503
|
|
|
|
|
|
|
|
|
504
|
0
|
|
|
|
|
|
$self->{'PutUpdateCallback'} = $callback_ref; |
|
505
|
|
|
|
|
|
|
} |
|
506
|
|
|
|
|
|
|
sub registerPutDoneCallback { |
|
507
|
0
|
|
|
0
|
0
|
|
my ($self,$callback_ref)=@_; |
|
508
|
|
|
|
|
|
|
|
|
509
|
0
|
|
|
|
|
|
$self->{'PutDoneCallback'} = $callback_ref; |
|
510
|
|
|
|
|
|
|
} |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
sub setup_protection { |
|
513
|
0
|
|
|
0
|
0
|
|
my ($self)=@_; |
|
514
|
0
|
0
|
|
|
|
|
if ($self->{'Encrypt'}) { |
|
|
0
|
|
|
|
|
|
|
|
515
|
0
|
|
|
|
|
|
$self->command("PBSZ 0");# TODO |
|
516
|
0
|
0
|
|
|
|
|
if ($self->{"EncryptData"}!=0) {$self->command("PROT P"); }; |
|
|
0
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
} else {return 1;}; |
|
518
|
|
|
|
|
|
|
}; |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
1; |
|
523
|
|
|
|
|
|
|
__END__ |