line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siffra::Transfers; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
53459
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
7
|
1
|
|
|
1
|
|
469
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
501
|
use Data::Dumper; |
|
1
|
|
|
|
|
5410
|
|
|
1
|
|
|
|
|
49
|
|
9
|
1
|
|
|
1
|
|
363
|
use DDP; |
|
1
|
|
|
|
|
32352
|
|
|
1
|
|
|
|
|
10
|
|
10
|
1
|
|
|
1
|
|
417
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
8268
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
1689
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
12
|
|
|
|
|
|
|
$Carp::Verbose = 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$| = 1; #autoflush |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use constant { |
17
|
|
|
|
|
|
|
FALSE => 0, |
18
|
|
|
|
|
|
|
TRUE => 1, |
19
|
1
|
|
50
|
|
|
74
|
DEBUG => $ENV{ DEBUG } // 0, |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
FILE_ALREADY_DOWNLOADED => -1, |
22
|
1
|
|
|
1
|
|
13
|
}; |
|
1
|
|
|
|
|
2
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
423
|
use Term::ProgressBar; |
|
1
|
|
|
|
|
58916
|
|
|
1
|
|
|
|
|
60
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
BEGIN |
27
|
|
|
|
|
|
|
{ |
28
|
1
|
|
|
1
|
|
24
|
binmode( STDOUT, ":encoding(UTF-8)" ); |
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
10
|
|
29
|
1
|
|
|
|
|
13213
|
binmode( STDERR, ":encoding(UTF-8)" ); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
437
|
require Siffra::Tools; |
32
|
1
|
|
|
1
|
|
8
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
33
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
107
|
|
34
|
1
|
|
|
|
|
5319
|
$VERSION = '0.07'; |
35
|
1
|
|
|
|
|
21
|
@ISA = qw(Siffra::Tools Exporter); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
38
|
1
|
|
|
|
|
3
|
@EXPORT = qw(); |
39
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw(); |
40
|
1
|
|
|
|
|
3209
|
%EXPORT_TAGS = (); |
41
|
|
|
|
|
|
|
} ## end BEGIN |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# TODO - Verificar o diretorio de Download para se não existir criar. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 C<new()> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Usage : $self->block_new_method() within text_pm_file() |
48
|
|
|
|
|
|
|
Purpose : Build 'new()' method as part of a pm file |
49
|
|
|
|
|
|
|
Returns : String holding sub new. |
50
|
|
|
|
|
|
|
Argument : $module: pointer to the module being built |
51
|
|
|
|
|
|
|
(as there can be more than one module built by EU::MM); |
52
|
|
|
|
|
|
|
for the primary module it is a pointer to $self |
53
|
|
|
|
|
|
|
Throws : n/a |
54
|
|
|
|
|
|
|
Comment : This method is a likely candidate for alteration in a subclass, |
55
|
|
|
|
|
|
|
e.g., pass a single hash-ref to new() instead of a list of |
56
|
|
|
|
|
|
|
parameters. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
1
|
1
|
80
|
$log->debug( "new", { progname => $0, pid => $$, perl_version => $], package => __PACKAGE__ } ); |
63
|
1
|
|
|
|
|
6
|
my ( $class, %parameters ) = @_; |
64
|
1
|
|
|
|
|
11
|
my $self = $class->SUPER::new( %parameters ); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
37
|
$self->_initialize( %parameters ); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
4
|
return $self; |
69
|
|
|
|
|
|
|
} ## end sub new |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _initialize() |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
|
6
|
$log->debug( "_initialize", { package => __PACKAGE__ } ); |
74
|
1
|
|
|
|
|
3
|
my ( $self, %parameters ) = @_; |
75
|
1
|
|
|
|
|
7
|
$self->SUPER::_initialize( %parameters ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->{ config } = { |
78
|
1
|
|
|
|
|
2979
|
protocol => undef, |
79
|
|
|
|
|
|
|
host => undef, |
80
|
|
|
|
|
|
|
user => undef, |
81
|
|
|
|
|
|
|
password => undef, |
82
|
|
|
|
|
|
|
port => undef, |
83
|
|
|
|
|
|
|
passive => undef, |
84
|
|
|
|
|
|
|
identity_file => undef, |
85
|
|
|
|
|
|
|
debug => undef, |
86
|
|
|
|
|
|
|
localDirectory => undef, |
87
|
|
|
|
|
|
|
directories => {}, |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
2
|
$self->{ connection } = undef; |
91
|
1
|
|
|
|
|
5
|
$self->{ json } = undef; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
94
|
|
|
|
|
|
|
# Tipos de protocolos suportados |
95
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
96
|
|
|
|
|
|
|
$self->{ supportedProtocols } = { |
97
|
1
|
|
|
|
|
10
|
'FTP' => { |
98
|
|
|
|
|
|
|
connect => 'connectFTP', |
99
|
|
|
|
|
|
|
getFiles => 'getFilesFTP', |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
'SFTP' => { |
102
|
|
|
|
|
|
|
connect => 'connectSFTP', |
103
|
|
|
|
|
|
|
getFiles => 'getFilesSFTP', |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
'LOCAL' => { |
106
|
|
|
|
|
|
|
connect => 'connectLOCAL', |
107
|
|
|
|
|
|
|
getFiles => 'getFilesLOCAL', |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
112
|
|
|
|
|
|
|
# Tipos de MIME-Types suportados |
113
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
114
|
|
|
|
|
|
|
$self->{ supportedMimeTypes } = { |
115
|
1
|
|
|
|
|
8
|
'application/x-tar-gz' => FALSE, # .tar.gz |
116
|
|
|
|
|
|
|
'application/x-gzip' => FALSE, # .tar.gz |
117
|
|
|
|
|
|
|
'application/x-bzip' => FALSE, # .bz2 |
118
|
|
|
|
|
|
|
'application/x-bzip2' => FALSE, # .bz2 |
119
|
|
|
|
|
|
|
'application/zip' => 'unZipFile', # .zip |
120
|
|
|
|
|
|
|
'application/x-rar-compressed' => FALSE, # .rar |
121
|
|
|
|
|
|
|
'application/x-tar' => FALSE, # .tar |
122
|
|
|
|
|
|
|
'application/x-7z-compressed' => FALSE, # .tar |
123
|
|
|
|
|
|
|
'application/pdf' => FALSE, # .pdf |
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
} ## end sub _initialize |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub END |
128
|
|
|
|
|
|
|
{ |
129
|
1
|
|
|
1
|
|
123
|
$log->debug( "END", { package => __PACKAGE__ } ); |
130
|
1
|
|
|
|
|
4
|
eval { $log->{ adapter }->{ dispatcher }->{ outputs }->{ Email }->flush; }; |
|
1
|
|
|
|
|
59
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#################################################### Sets |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $setProtocol = sub { |
136
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
if ( !$self->{ supportedProtocols }->{ uc( $value ) } ) |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
$log->error( "Protocolo [ $value ] não suportado..." ); |
141
|
|
|
|
|
|
|
return FALSE; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
return $self->{ config }->{ protocol } = uc( $value ); |
145
|
|
|
|
|
|
|
}; |
146
|
|
|
|
|
|
|
my $setHost = sub { |
147
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
148
|
|
|
|
|
|
|
return $self->{ config }->{ host } = $value; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
my $setUser = sub { |
151
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
152
|
|
|
|
|
|
|
return $self->{ config }->{ user } = $value; |
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
my $setPassword = sub { |
155
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
156
|
|
|
|
|
|
|
return $self->{ config }->{ password } = $value; |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
my $setPort = sub { |
159
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
160
|
|
|
|
|
|
|
return $self->{ config }->{ port } = $value; |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
my $setDebug = sub { |
163
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
164
|
|
|
|
|
|
|
return $self->{ config }->{ debug } = $value; |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
my $setPassive = sub { |
167
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
168
|
|
|
|
|
|
|
return $self->{ config }->{ passive } = $value; |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
my $setSsl = sub { |
171
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
172
|
|
|
|
|
|
|
return $self->{ config }->{ ssl } = $value; |
173
|
|
|
|
|
|
|
}; |
174
|
|
|
|
|
|
|
my $setIdentityFile = sub { |
175
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
176
|
|
|
|
|
|
|
return $self->{ config }->{ identity_file } = $value; |
177
|
|
|
|
|
|
|
}; |
178
|
|
|
|
|
|
|
my $setLocalDirectory = sub { |
179
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
180
|
|
|
|
|
|
|
return $self->{ config }->{ localDirectory } = ( $value // './download/' ); |
181
|
|
|
|
|
|
|
}; |
182
|
|
|
|
|
|
|
my $setDirectories = sub { |
183
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
$self->{ config }->{ directories } = undef; |
186
|
|
|
|
|
|
|
while ( my ( $remoteDirectory, $configuration ) = each( %{ $value } ) ) |
187
|
|
|
|
|
|
|
{ |
188
|
|
|
|
|
|
|
$configuration->{ remoteDirectory } = $remoteDirectory; |
189
|
|
|
|
|
|
|
return FALSE unless $self->addDirectory( $configuration ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
return TRUE; |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#################################################### Sets |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 C<addDirectory()> |
197
|
|
|
|
|
|
|
=cut |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
200
|
|
|
|
|
|
|
# Adiciona uma configuracao para upload |
201
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
202
|
|
|
|
|
|
|
sub addDirectory |
203
|
|
|
|
|
|
|
{ |
204
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $configuration ) = @_; |
205
|
|
|
|
|
|
|
|
206
|
0
|
0
|
|
|
|
0
|
return FALSE unless $configuration->{ fileNameRule }; |
207
|
0
|
0
|
|
|
|
0
|
return FALSE unless $configuration->{ remoteDirectory }; |
208
|
0
|
0
|
|
|
|
0
|
return FALSE unless ref $configuration->{ downloadedFiles } eq 'HASH'; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
#{ |
211
|
|
|
|
|
|
|
# downloadedFiles {}, |
212
|
|
|
|
|
|
|
# fileNameRule "VALID_RETORNO_.*", |
213
|
|
|
|
|
|
|
# remoteDirectory "/valid/upload/" |
214
|
|
|
|
|
|
|
#} |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
0
|
$self->{ config }->{ directories }->{ $configuration->{ remoteDirectory } } = $configuration; |
217
|
0
|
|
|
|
|
0
|
return TRUE; |
218
|
|
|
|
|
|
|
} ## end sub addDirectory |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 C<cleanDirectories()> |
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
224
|
|
|
|
|
|
|
# Limpa os directories |
225
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
226
|
|
|
|
|
|
|
sub cleanDirectories |
227
|
|
|
|
|
|
|
{ |
228
|
0
|
|
|
0
|
1
|
0
|
my ( $self ) = @_; |
229
|
0
|
|
|
|
|
0
|
return $self->{ config }->{ directories } = {}; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 C<setConfig()> |
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub setConfig() |
236
|
|
|
|
|
|
|
{ |
237
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
$self->$setProtocol( $parameters{ protocol } ); |
240
|
0
|
|
|
|
|
0
|
$self->$setHost( $parameters{ host } ); |
241
|
0
|
|
|
|
|
0
|
$self->$setUser( $parameters{ user } ); |
242
|
0
|
|
|
|
|
0
|
$self->$setPassword( $parameters{ password } ); |
243
|
0
|
|
|
|
|
0
|
$self->$setPort( $parameters{ port } ); |
244
|
0
|
|
|
|
|
0
|
$self->$setDebug( $parameters{ debug } ); |
245
|
0
|
|
|
|
|
0
|
$self->$setPassive( $parameters{ passive } ); |
246
|
0
|
|
|
|
|
0
|
$self->$setSsl( $parameters{ ssl } ); |
247
|
0
|
|
|
|
|
0
|
$self->$setIdentityFile( $parameters{ identity_file } ); |
248
|
0
|
|
|
|
|
0
|
$self->$setLocalDirectory( $parameters{ localDirectory } ); |
249
|
0
|
|
|
|
|
0
|
$self->$setDirectories( $parameters{ directories } ); |
250
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
0
|
return $self->testConfig( %parameters ); |
252
|
|
|
|
|
|
|
} ## end sub setConfig |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 C<testConfig()> |
255
|
|
|
|
|
|
|
=cut |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub testConfig() |
258
|
|
|
|
|
|
|
{ |
259
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
260
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
return TRUE; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 C<connect()> |
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub connect() |
268
|
|
|
|
|
|
|
{ |
269
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
270
|
|
|
|
|
|
|
|
271
|
0
|
0
|
|
|
|
0
|
return FALSE unless $self->testConfig(); |
272
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
0
|
my $connectSub = $self->{ supportedProtocols }->{ uc $self->{ config }->{ protocol } }->{ connect }; |
274
|
|
|
|
|
|
|
|
275
|
0
|
|
|
|
|
0
|
return $self->$connectSub( %parameters ); |
276
|
|
|
|
|
|
|
} ## end sub connect |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=head2 C<connectFTP()> |
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub connectFTP () |
282
|
|
|
|
|
|
|
{ |
283
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
284
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
0
|
my $moduleConn = 'Net::FTP'; |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
0
|
eval "require $moduleConn;"; |
288
|
|
|
|
|
|
|
|
289
|
0
|
0
|
|
|
|
0
|
if ( $@ ) |
290
|
|
|
|
|
|
|
{ |
291
|
0
|
|
|
|
|
0
|
$log->error( "Erro ao usar o módulo [ $moduleConn ]..." . $@ ); |
292
|
0
|
|
|
|
|
0
|
return FALSE; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
my %args = ( |
296
|
|
|
|
|
|
|
Host => $self->{ config }->{ host }, |
297
|
|
|
|
|
|
|
Port => $self->{ config }->{ port } // 21, |
298
|
|
|
|
|
|
|
Debug => $self->{ config }->{ debug }, |
299
|
0
|
|
0
|
|
|
0
|
Passive => $self->{ config }->{ passive } // 1, |
|
|
|
0
|
|
|
|
|
300
|
|
|
|
|
|
|
); |
301
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
0
|
$log->info( "Conectando no FTP [ $args{Host}\:$args{Port} ]" ); |
303
|
0
|
|
|
|
|
0
|
$self->{ connection } = Net::FTP->new( %args ); |
304
|
|
|
|
|
|
|
|
305
|
0
|
0
|
|
|
|
0
|
if ( $self->{ connection } ) |
306
|
|
|
|
|
|
|
{ |
307
|
0
|
0
|
|
|
|
0
|
$self->{ connection }->starttls() if $self->{ config }->{ ssl }; |
308
|
0
|
|
|
|
|
0
|
my $user = $self->{ config }->{ user }; |
309
|
0
|
|
|
|
|
0
|
my $password = $self->{ config }->{ password }; |
310
|
0
|
0
|
|
|
|
0
|
if ( !$self->{ connection }->login( $user, $password ) ) |
311
|
|
|
|
|
|
|
{ |
312
|
0
|
|
|
|
|
0
|
$log->error( $self->{ connection }->message ); |
313
|
0
|
|
|
|
|
0
|
return FALSE; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
else |
316
|
|
|
|
|
|
|
{ |
317
|
0
|
|
|
|
|
0
|
$log->info( "Conexão feita com sucesso no FTP [ ${user}\@$args{Host} ]..." ); |
318
|
0
|
|
|
|
|
0
|
return $self->{ connection }; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
} ## end if ( $self->{ connection...}) |
321
|
|
|
|
|
|
|
else |
322
|
|
|
|
|
|
|
{ |
323
|
0
|
|
|
|
|
0
|
$log->error( "Não foi possÃvel criar o objeto FTP..." ); |
324
|
0
|
|
|
|
|
0
|
return FALSE; |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
0
|
|
|
|
|
0
|
return FALSE; |
328
|
|
|
|
|
|
|
} ## end sub connectFTP |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head2 C<connectSFTP()> |
331
|
|
|
|
|
|
|
=cut |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
sub connectSFTP () |
334
|
|
|
|
|
|
|
{ |
335
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
336
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
0
|
my $moduleConn = 'Net::SFTP::Foreign'; |
338
|
|
|
|
|
|
|
|
339
|
0
|
|
|
|
|
0
|
eval "require $moduleConn;"; |
340
|
|
|
|
|
|
|
|
341
|
0
|
0
|
|
|
|
0
|
if ( $@ ) |
342
|
|
|
|
|
|
|
{ |
343
|
0
|
|
|
|
|
0
|
$log->error( "Erro ao usar o módulo [ $moduleConn ]..." . $@ ); |
344
|
0
|
|
|
|
|
0
|
return FALSE; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
my %args = ( |
348
|
|
|
|
|
|
|
host => $self->{ config }->{ host }, |
349
|
|
|
|
|
|
|
user => $self->{ config }->{ user }, |
350
|
|
|
|
|
|
|
password => $self->{ config }->{ password }, |
351
|
0
|
|
0
|
|
|
0
|
port => $self->{ config }->{ port } // 22, |
352
|
|
|
|
|
|
|
autodie => 0, |
353
|
|
|
|
|
|
|
more => [ |
354
|
|
|
|
|
|
|
-o => 'StrictHostKeyChecking no', |
355
|
|
|
|
|
|
|
-o => 'HostKeyAlgorithms +ssh-dss', |
356
|
|
|
|
|
|
|
], |
357
|
|
|
|
|
|
|
); |
358
|
|
|
|
|
|
|
|
359
|
0
|
0
|
|
|
|
0
|
push @{ $args{ key_path } }, $self->{ config }->{ identity_file } if $self->{ config }->{ identity_file }; |
|
0
|
|
|
|
|
0
|
|
360
|
0
|
0
|
|
|
|
0
|
push @{ $args{ more } }, '-v' if ( $self->{ config }->{ debug } ); |
|
0
|
|
|
|
|
0
|
|
361
|
|
|
|
|
|
|
|
362
|
0
|
|
|
|
|
0
|
$log->info( "Conectando no SFTP [ $args{host}\:$args{port} ]" ); |
363
|
0
|
|
|
|
|
0
|
$self->{ connection } = eval { Net::SFTP::Foreign->new( %args ); }; |
|
0
|
|
|
|
|
0
|
|
364
|
|
|
|
|
|
|
|
365
|
0
|
0
|
|
|
|
0
|
if ( $@ ) |
|
|
0
|
|
|
|
|
|
366
|
|
|
|
|
|
|
{ |
367
|
0
|
|
|
|
|
0
|
$log->error( $@ ); |
368
|
0
|
|
|
|
|
0
|
$log->error( "Não foi possÃvel criar o objeto SFTP..." ); |
369
|
0
|
|
|
|
|
0
|
return FALSE; |
370
|
|
|
|
|
|
|
} ## end if ( $@ ) |
371
|
|
|
|
|
|
|
elsif ( $self->{ connection }->error ) |
372
|
|
|
|
|
|
|
{ |
373
|
0
|
|
|
|
|
0
|
$log->error( $self->{ connection }->error ); |
374
|
0
|
|
|
|
|
0
|
return FALSE; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
else |
377
|
|
|
|
|
|
|
{ |
378
|
0
|
|
|
|
|
0
|
$log->info( "Conexão feita com sucesso no SFTP [ $args{user}\@$args{host} ]..." ); |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
|
381
|
0
|
|
|
|
|
0
|
return $self->{ connection }; |
382
|
|
|
|
|
|
|
} ## end sub connectSFTP |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
=head2 C<connectLocal()> |
385
|
|
|
|
|
|
|
=cut |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub connectLocal () |
388
|
|
|
|
|
|
|
{ |
389
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
390
|
|
|
|
|
|
|
|
391
|
0
|
|
|
|
|
0
|
return TRUE; |
392
|
|
|
|
|
|
|
} |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=head2 C<getActiveDirectory()> |
395
|
|
|
|
|
|
|
=cut |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
398
|
|
|
|
|
|
|
# Pega o diretorio atual |
399
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
400
|
|
|
|
|
|
|
sub getActiveDirectory() |
401
|
|
|
|
|
|
|
{ |
402
|
0
|
|
|
0
|
1
|
0
|
my ( $self ) = @_; |
403
|
|
|
|
|
|
|
|
404
|
0
|
0
|
|
|
|
0
|
$self->{ config }->{ activeDirectory } = $self->{ config }->{ activeDirectory } ? $self->{ config }->{ activeDirectory } : '/'; |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
0
|
return $self->{ config }->{ activeDirectory }; |
407
|
|
|
|
|
|
|
} ## end sub getActiveDirectory |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
=head2 C<setActiveDirectory()> |
410
|
|
|
|
|
|
|
=cut |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
413
|
|
|
|
|
|
|
# Pega o diretorio atual |
414
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
415
|
|
|
|
|
|
|
sub setActiveDirectory() |
416
|
|
|
|
|
|
|
{ |
417
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $directory ) = @_; |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
0
|
return $self->{ config }->{ activeDirectory } = $directory; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=head2 C<getFiles()> |
423
|
|
|
|
|
|
|
=cut |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
sub getFiles |
426
|
|
|
|
|
|
|
{ |
427
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
428
|
|
|
|
|
|
|
|
429
|
0
|
0
|
|
|
|
0
|
return FALSE unless ( $self->testConfig() ); |
430
|
|
|
|
|
|
|
|
431
|
0
|
|
|
|
|
0
|
my $protocol = uc $self->{ config }->{ protocol }; |
432
|
0
|
|
|
|
|
0
|
my $getFilesSub = $self->{ supportedProtocols }->{ $protocol }->{ getFiles }; |
433
|
0
|
|
|
|
|
0
|
my $retorno; |
434
|
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
0
|
while ( my ( $directory, $directoryConfiguration ) = each( %{ $self->{ config }->{ directories } } ) ) |
|
0
|
|
|
|
|
0
|
|
436
|
|
|
|
|
|
|
{ |
437
|
0
|
|
|
|
|
0
|
$self->setActiveDirectory( $directory ); |
438
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
0
|
$retorno->{ $directory } = $self->$getFilesSub( %parameters ); |
440
|
|
|
|
|
|
|
|
441
|
0
|
0
|
0
|
|
|
0
|
if ( ( ref $retorno->{ $directory } eq 'HASH' ) && ( $retorno->{ $directory }->{ error } == 0 ) && ( $directoryConfiguration->{ 'unpack' } ) ) |
|
|
|
0
|
|
|
|
|
442
|
|
|
|
|
|
|
{ |
443
|
0
|
|
|
|
|
0
|
foreach my $file ( @{ $retorno->{ $directory }->{ files } } ) |
|
0
|
|
|
|
|
0
|
|
444
|
|
|
|
|
|
|
{ |
445
|
0
|
0
|
0
|
|
|
0
|
if ( ref $file eq 'HASH' && $file->{ error } == 0 ) |
446
|
|
|
|
|
|
|
{ |
447
|
0
|
|
|
|
|
0
|
$file->{ 'unpack' } = $self->unPackFile( conf => $directoryConfiguration, file => $file ); |
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
} ## end foreach my $file ( @{ $retorno...}) |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
} ## end if ( ( ref $retorno->{...})) |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
} ## end while ( my ( $directory, ...)) |
455
|
|
|
|
|
|
|
|
456
|
0
|
|
|
|
|
0
|
return $retorno; |
457
|
|
|
|
|
|
|
} ## end sub getFiles |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=head2 C<getFilesFTP()> |
460
|
|
|
|
|
|
|
=cut |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
sub getFilesFTP() |
463
|
|
|
|
|
|
|
{ |
464
|
0
|
|
|
0
|
1
|
0
|
$log->debug( "getFilesFTP", { package => __PACKAGE__ } ); |
465
|
0
|
|
|
|
|
0
|
my ( $self, %parameters ) = @_; |
466
|
|
|
|
|
|
|
|
467
|
0
|
|
|
|
|
0
|
my $retorno = { |
468
|
|
|
|
|
|
|
error => 0, |
469
|
|
|
|
|
|
|
message => 'ok', |
470
|
|
|
|
|
|
|
downloadedFiles => [], |
471
|
|
|
|
|
|
|
notDownloadedFiles => [] |
472
|
|
|
|
|
|
|
}; |
473
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
0
|
my $remoteDirectory = $self->getActiveDirectory(); |
475
|
0
|
|
|
|
|
0
|
my $configuration = $self->{ config }->{ directories }->{ $remoteDirectory }; |
476
|
0
|
|
|
|
|
0
|
my $localDirectory = $self->{ config }->{ localDirectory }; |
477
|
|
|
|
|
|
|
|
478
|
0
|
|
|
|
|
0
|
$log->info( "Entrando em [ getFilesFTP ] para o diretório [ $remoteDirectory ]..." ); |
479
|
|
|
|
|
|
|
|
480
|
0
|
0
|
|
|
|
0
|
unless ( $self->{ connection }->cwd( $remoteDirectory ) ) |
481
|
|
|
|
|
|
|
{ |
482
|
|
|
|
|
|
|
return { |
483
|
|
|
|
|
|
|
error => 1, |
484
|
|
|
|
|
|
|
message => $self->{ connection }->message() |
485
|
0
|
|
|
|
|
0
|
}; |
486
|
|
|
|
|
|
|
} ## end unless ( $self->{ connection...}) |
487
|
|
|
|
|
|
|
|
488
|
0
|
0
|
|
|
|
0
|
unless ( $self->{ connection }->binary() ) |
489
|
|
|
|
|
|
|
{ |
490
|
|
|
|
|
|
|
return { |
491
|
|
|
|
|
|
|
error => 1, |
492
|
|
|
|
|
|
|
message => $self->{ connection }->message() |
493
|
0
|
|
|
|
|
0
|
}; |
494
|
|
|
|
|
|
|
} ## end unless ( $self->{ connection...}) |
495
|
|
|
|
|
|
|
|
496
|
0
|
|
|
|
|
0
|
my $remoteFiles = $self->{ connection }->ls(); |
497
|
|
|
|
|
|
|
|
498
|
0
|
0
|
0
|
|
|
0
|
if ( ( !defined $remoteFiles ) && ( $self->{ connection }->message() =~ /No files found/ ) ) |
|
|
0
|
|
|
|
|
|
499
|
|
|
|
|
|
|
{ |
500
|
|
|
|
|
|
|
return { |
501
|
|
|
|
|
|
|
error => 0, |
502
|
0
|
|
|
|
|
0
|
message => $self->{ connection }->message(), |
503
|
|
|
|
|
|
|
files => [] |
504
|
|
|
|
|
|
|
}; |
505
|
|
|
|
|
|
|
} ## end if ( ( !defined $remoteFiles...)) |
506
|
|
|
|
|
|
|
elsif ( !defined $remoteFiles ) |
507
|
|
|
|
|
|
|
{ |
508
|
|
|
|
|
|
|
return { |
509
|
|
|
|
|
|
|
error => 1, |
510
|
0
|
|
0
|
|
|
0
|
message => ( $self->{ connection }->message() // '' ) |
511
|
|
|
|
|
|
|
}; |
512
|
|
|
|
|
|
|
} ## end elsif ( !defined $remoteFiles...) |
513
|
|
|
|
|
|
|
else |
514
|
|
|
|
|
|
|
{ |
515
|
0
|
|
|
|
|
0
|
foreach my $remoteFile ( @{ $remoteFiles } ) |
|
0
|
|
|
|
|
0
|
|
516
|
|
|
|
|
|
|
{ |
517
|
0
|
|
|
|
|
0
|
my $status = $self->canDownloadFile( fileName => $remoteFile ); |
518
|
0
|
0
|
|
|
|
0
|
if ( $status < 0 ) |
519
|
|
|
|
|
|
|
{ |
520
|
0
|
|
|
|
|
0
|
push( @{ $retorno->{ notDownloadedFiles } }, { name => $remoteFile, status => $status } ); |
|
0
|
|
|
|
|
0
|
|
521
|
0
|
|
|
|
|
0
|
next; |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
|
524
|
0
|
|
|
|
|
0
|
$log->info( "Baixando o arquivo [ $remoteFile ]..." ); |
525
|
|
|
|
|
|
|
|
526
|
0
|
|
|
|
|
0
|
my $localFile = $localDirectory . '/' . $remoteFile; |
527
|
0
|
|
|
|
|
0
|
my $get = eval { $self->{ connection }->get( $remoteFile, $localFile ); }; |
|
0
|
|
|
|
|
0
|
|
528
|
|
|
|
|
|
|
|
529
|
0
|
|
|
|
|
0
|
my $file = { |
530
|
|
|
|
|
|
|
error => 0, |
531
|
|
|
|
|
|
|
message => '', |
532
|
|
|
|
|
|
|
name => $remoteFile, |
533
|
|
|
|
|
|
|
file_size => -1, |
534
|
|
|
|
|
|
|
md5sum => undef, |
535
|
|
|
|
|
|
|
filePath => $localFile |
536
|
|
|
|
|
|
|
}; |
537
|
|
|
|
|
|
|
|
538
|
0
|
0
|
|
|
|
0
|
if ( !$get ) |
539
|
|
|
|
|
|
|
{ |
540
|
0
|
|
|
|
|
0
|
$file->{ error } = 1; |
541
|
0
|
|
|
|
|
0
|
$file->{ message } = $self->{ connection }->message(); |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
else |
544
|
|
|
|
|
|
|
{ |
545
|
0
|
|
|
|
|
0
|
$file->{ file_size } = -s $localFile; |
546
|
0
|
|
|
|
|
0
|
my $md5 = $self->getFileMD5( file => $localFile ); |
547
|
0
|
|
|
|
|
0
|
$file->{ md5sum } = $md5; |
548
|
|
|
|
|
|
|
} ## end else [ if ( !$get ) ] |
549
|
|
|
|
|
|
|
|
550
|
0
|
|
|
|
|
0
|
push( @{ $retorno->{ downloadedFiles } }, $file ); |
|
0
|
|
|
|
|
0
|
|
551
|
0
|
0
|
|
|
|
0
|
last() if ( $parameters{ only_one_file } ); |
552
|
|
|
|
|
|
|
} ## end foreach my $remoteFile ( @{...}) |
553
|
|
|
|
|
|
|
} ## end else [ if ( ( !defined $remoteFiles...))] |
554
|
|
|
|
|
|
|
|
555
|
0
|
|
|
|
|
0
|
return $retorno; |
556
|
|
|
|
|
|
|
} ## end sub getFilesFTP |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
=head2 C<canDownloadFile()> |
559
|
|
|
|
|
|
|
=cut |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
sub canDownloadFile() |
562
|
|
|
|
|
|
|
{ |
563
|
0
|
|
|
0
|
1
|
0
|
$log->debug( "canDownloadFile", { package => __PACKAGE__ } ); |
564
|
0
|
|
|
|
|
0
|
my ( $self, %parameters ) = @_; |
565
|
0
|
|
|
|
|
0
|
my $fileName = $parameters{ fileName }; |
566
|
|
|
|
|
|
|
|
567
|
0
|
|
|
|
|
0
|
my $activeDownload = $self->{ config }->{ directories }->{ $self->getActiveDirectory() }; |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
# ja foi baixado |
570
|
0
|
0
|
|
|
|
0
|
return -1 if ( $activeDownload->{ downloadedFiles }{ $fileName } ); |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# nao bate com a regra de nomes |
573
|
0
|
0
|
|
|
|
0
|
if ( defined $activeDownload->{ fileNameRule } ) |
574
|
|
|
|
|
|
|
{ |
575
|
0
|
|
|
|
|
0
|
$self->{ message } = "Arquivo [ $fileName ] não bate com a regra de filename_pattern."; |
576
|
0
|
0
|
|
|
|
0
|
return -2 if ( $fileName !~ /$activeDownload->{fileNameRule}/ ); |
577
|
0
|
|
|
|
|
0
|
return TRUE; |
578
|
|
|
|
|
|
|
} ## end if ( defined $activeDownload...) |
579
|
|
|
|
|
|
|
else |
580
|
|
|
|
|
|
|
{ |
581
|
0
|
|
|
|
|
0
|
$log->error( "Não existe regra para o nome do arquivo......" ); |
582
|
0
|
|
|
|
|
0
|
return FALSE; |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
|
585
|
0
|
|
|
|
|
0
|
return FALSE; |
586
|
|
|
|
|
|
|
} ## end sub canDownloadFile |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=head2 C<getFilesSFTP()> |
589
|
|
|
|
|
|
|
=cut |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
sub getFilesSFTP() |
592
|
|
|
|
|
|
|
{ |
593
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
594
|
|
|
|
|
|
|
|
595
|
0
|
|
|
|
|
0
|
my $retorno = { |
596
|
|
|
|
|
|
|
error => 0, |
597
|
|
|
|
|
|
|
message => 'ok', |
598
|
|
|
|
|
|
|
downloadedFiles => [], |
599
|
|
|
|
|
|
|
notDownloadedFiles => [] |
600
|
|
|
|
|
|
|
}; |
601
|
|
|
|
|
|
|
|
602
|
0
|
|
|
|
|
0
|
my $remoteDirectory = $self->getActiveDirectory(); |
603
|
0
|
|
|
|
|
0
|
my $configuration = $self->{ config }->{ directories }->{ $remoteDirectory }; |
604
|
0
|
|
|
|
|
0
|
my $localDirectory = $self->{ config }->{ localDirectory }; #'./download/'; |
605
|
|
|
|
|
|
|
|
606
|
0
|
|
|
|
|
0
|
$log->info( "Entrando em [ getFilesSFTP ] para o diretório [ $remoteDirectory ]..." ); |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
my $ls = $self->{ connection }->ls( |
609
|
|
|
|
|
|
|
$remoteDirectory, |
610
|
|
|
|
|
|
|
wanted => sub { |
611
|
0
|
|
|
0
|
|
0
|
my $entry = $_[ 1 ]; |
612
|
0
|
|
0
|
|
|
0
|
return ( $entry->{ a }->{ size } > 0 and ( $entry->{ filename } =~ qr/$configuration->{ fileNameRule }/i ) and ref $configuration->{ downloadedFiles } eq 'HASH' and !$configuration->{ downloadedFiles }->{ $entry->{ filename } } ); |
613
|
|
|
|
|
|
|
} |
614
|
0
|
|
|
|
|
0
|
); |
615
|
|
|
|
|
|
|
|
616
|
0
|
0
|
|
|
|
0
|
if ( $ls ) |
617
|
|
|
|
|
|
|
{ |
618
|
|
|
|
|
|
|
my $callback = sub { |
619
|
0
|
|
|
0
|
|
0
|
my ( $sftp, $data, $offset, $size, $progress ) = @_; |
620
|
0
|
0
|
|
|
|
0
|
$offset = $size if ( $offset >= $size ); |
621
|
0
|
|
|
|
|
0
|
$progress->update( $offset ); |
622
|
0
|
|
|
|
|
0
|
}; |
623
|
|
|
|
|
|
|
|
624
|
0
|
|
|
|
|
0
|
foreach my $remoteFile ( @{ $ls } ) |
|
0
|
|
|
|
|
0
|
|
625
|
|
|
|
|
|
|
{ |
626
|
|
|
|
|
|
|
my $progress = Term::ProgressBar->new( |
627
|
|
|
|
|
|
|
{ |
628
|
|
|
|
|
|
|
name => $remoteFile->{ filename } . " ( $remoteFile->{ a }->{ size } ) ", |
629
|
|
|
|
|
|
|
count => $remoteFile->{ a }->{ size }, |
630
|
0
|
|
|
|
|
0
|
ETA => 'linear', |
631
|
|
|
|
|
|
|
remove => 1, |
632
|
|
|
|
|
|
|
silent => !DEBUG, |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
); |
635
|
0
|
|
|
|
|
0
|
$progress->minor( 0 ); |
636
|
|
|
|
|
|
|
|
637
|
0
|
|
|
0
|
|
0
|
my %options = ( callback => sub { &$callback( @_, $progress ); }, mkpath => 1 ); |
|
0
|
|
|
|
|
0
|
|
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
#$log->debug( $remoteDirectory . $remoteFile->{ filename } ); |
640
|
0
|
|
|
|
|
0
|
$self->{ connection }->get( $remoteDirectory . $remoteFile->{ filename }, $localDirectory . $remoteFile->{ filename }, %options ); |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
my $downloadedFile = { |
643
|
|
|
|
|
|
|
error => FALSE, |
644
|
|
|
|
|
|
|
message => undef, |
645
|
|
|
|
|
|
|
filename => $remoteFile->{ filename }, |
646
|
|
|
|
|
|
|
size => $remoteFile->{ a }->{ size }, |
647
|
|
|
|
|
|
|
md5sum => undef, |
648
|
|
|
|
|
|
|
filePath => $localDirectory . $remoteFile->{ filename }, |
649
|
0
|
|
|
|
|
0
|
}; |
650
|
|
|
|
|
|
|
|
651
|
0
|
0
|
|
|
|
0
|
if ( $self->{ connection }->error ) |
652
|
|
|
|
|
|
|
{ |
653
|
0
|
|
|
|
|
0
|
$log->error( $self->{ connection }->error ); |
654
|
0
|
|
|
|
|
0
|
$log->error( $remoteDirectory . $remoteFile->{ filename } ); |
655
|
0
|
|
|
|
|
0
|
$downloadedFile->{ error } = TRUE; |
656
|
0
|
|
|
|
|
0
|
$downloadedFile->{ message } = $self->{ connection }->error; |
657
|
0
|
|
|
|
|
0
|
$downloadedFile->{ remoteFile } = $remoteDirectory . $remoteFile->{ filename }; |
658
|
|
|
|
|
|
|
} ## end if ( $self->{ connection...}) |
659
|
|
|
|
|
|
|
else |
660
|
|
|
|
|
|
|
{ |
661
|
0
|
|
|
|
|
0
|
$downloadedFile->{ md5sum } = $self->getFileMD5( file => $localDirectory . $remoteFile->{ filename } ); |
662
|
0
|
|
|
|
|
0
|
$downloadedFile->{ message } = 'Ok'; |
663
|
0
|
|
|
|
|
0
|
$log->info( "Download do arquivo [ $downloadedFile->{ filename } ] feito com sucesso..." ); |
664
|
|
|
|
|
|
|
} ## end else [ if ( $self->{ connection...})] |
665
|
|
|
|
|
|
|
|
666
|
0
|
|
|
|
|
0
|
push( @{ $retorno->{ downloadedFiles } }, $downloadedFile ); |
|
0
|
|
|
|
|
0
|
|
667
|
|
|
|
|
|
|
} ## end foreach my $remoteFile ( @{...}) |
668
|
|
|
|
|
|
|
} ## end if ( $ls ) |
669
|
|
|
|
|
|
|
else |
670
|
|
|
|
|
|
|
{ |
671
|
0
|
|
|
|
|
0
|
$log->warn( 'Nenhuma arquivo para ser baixado...' ); |
672
|
|
|
|
|
|
|
} |
673
|
|
|
|
|
|
|
|
674
|
0
|
|
|
|
|
0
|
return $retorno; |
675
|
|
|
|
|
|
|
} ## end sub getFilesSFTP |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=head2 C<getFilesLOCAL()> |
678
|
|
|
|
|
|
|
=cut |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
sub getFilesLOCAL() |
681
|
|
|
|
|
|
|
{ |
682
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
683
|
0
|
|
|
|
|
0
|
return TRUE; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
687
|
|
|
|
|
|
|
# Descompacta arquivos |
688
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
689
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
=head2 C<unPackFile()> |
691
|
|
|
|
|
|
|
=cut |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
sub unPackFile() |
694
|
|
|
|
|
|
|
{ |
695
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %parameters ) = @_; |
696
|
0
|
|
|
|
|
0
|
my $mmt = $parameters{ conf }{ 'MIME-Type' }; |
697
|
|
|
|
|
|
|
|
698
|
0
|
|
|
|
|
0
|
my $files = []; |
699
|
0
|
0
|
|
|
|
0
|
if ( !$self->{ supportedMimeTypes }->{ $mmt } == FALSE ) |
700
|
|
|
|
|
|
|
{ |
701
|
|
|
|
|
|
|
my $unPackParam = { |
702
|
|
|
|
|
|
|
fileName => $parameters{ file }{ file_path }, |
703
|
|
|
|
|
|
|
out_path => $parameters{ conf }{ unpackDirectory } |
704
|
0
|
|
|
|
|
0
|
}; |
705
|
|
|
|
|
|
|
|
706
|
0
|
|
|
|
|
0
|
my $subname = $self->{ supportedMimeTypes }->{ $mmt }; |
707
|
0
|
|
|
|
|
0
|
$files = $self->$subname( $unPackParam ); |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
} ## end if ( !$self->{ supportedMimeTypes...}) |
710
|
|
|
|
|
|
|
else |
711
|
|
|
|
|
|
|
{ |
712
|
0
|
|
|
|
|
0
|
return { message => "MIME-Type $mmt não suportado", error => 1 }; |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
0
|
|
|
|
|
0
|
return { error => 0, files => $files }; |
716
|
|
|
|
|
|
|
} ## end sub unPackFile |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
719
|
|
|
|
|
|
|
# Descompacta arquivos ZIP |
720
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=head2 C<unZipFile()> |
723
|
|
|
|
|
|
|
=cut |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
sub unZipFile() |
726
|
|
|
|
|
|
|
{ |
727
|
|
|
|
|
|
|
|
728
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $param ) = @_; |
729
|
|
|
|
|
|
|
|
730
|
0
|
|
|
|
|
0
|
my $cmd = "unzip -o -b \"$param->{fileName}\" -d \"$param->{out_path}\""; |
731
|
0
|
|
|
|
|
0
|
my @files = `$cmd`; |
732
|
|
|
|
|
|
|
|
733
|
0
|
|
|
|
|
0
|
my $unpack = []; |
734
|
|
|
|
|
|
|
|
735
|
0
|
|
|
|
|
0
|
foreach ( @files ) |
736
|
|
|
|
|
|
|
{ |
737
|
0
|
0
|
|
|
|
0
|
next unless ( $_ =~ /inflating:\s(.+)$/ ); |
738
|
0
|
|
|
|
|
0
|
my $fileName = $1; |
739
|
0
|
|
|
|
|
0
|
$fileName =~ s/(^\s*)|(\s*$)//g; |
740
|
0
|
|
|
|
|
0
|
push( @{ $unpack }, $fileName ); |
|
0
|
|
|
|
|
0
|
|
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
} ## end foreach ( @files ) |
743
|
|
|
|
|
|
|
|
744
|
0
|
|
|
|
|
0
|
return $unpack; |
745
|
|
|
|
|
|
|
} ## end sub unZipFile |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
sub DESTROY |
748
|
|
|
|
|
|
|
{ |
749
|
1
|
|
|
1
|
|
561
|
my ( $self, %parameters ) = @_; |
750
|
1
|
|
|
|
|
10
|
$log->debug( 'DESTROY', { package => __PACKAGE__, GLOBAL_PHASE => ${^GLOBAL_PHASE}, blessed => FALSE } ); |
751
|
1
|
50
|
|
|
|
7
|
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; |
752
|
|
|
|
|
|
|
|
753
|
1
|
50
|
33
|
|
|
10
|
if ( blessed( $self ) && $self->isa( __PACKAGE__ ) ) |
754
|
|
|
|
|
|
|
{ |
755
|
1
|
|
|
|
|
9
|
$self->SUPER::DESTROY( %parameters ); |
756
|
1
|
|
|
|
|
26
|
$log->debug( "DESTROY", { package => __PACKAGE__, GLOBAL_PHASE => ${^GLOBAL_PHASE}, blessed => TRUE } ); |
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
else |
759
|
|
|
|
|
|
|
{ |
760
|
|
|
|
|
|
|
# TODO |
761
|
|
|
|
|
|
|
} |
762
|
|
|
|
|
|
|
} ## end sub DESTROY |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
765
|
|
|
|
|
|
|
## Below is the stub of documentation for your module. |
766
|
|
|
|
|
|
|
## You better edit it! |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=encoding UTF-8 |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
=head1 NAME |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
Siffra::Transfers - File transfers module |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
=head1 SYNOPSIS |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
use Siffra::Transfers; |
778
|
|
|
|
|
|
|
blah blah blah |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
=head1 DESCRIPTION |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
Stub documentation for this module was created by ExtUtils::ModuleMaker. |
784
|
|
|
|
|
|
|
It looks like the author of the extension was negligent enough |
785
|
|
|
|
|
|
|
to leave the stub unedited. |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
Blah blah blah. |
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
=head1 USAGE |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=head1 BUGS |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
=head1 SUPPORT |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
=head1 AUTHOR |
803
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
Luiz Benevenuto |
805
|
|
|
|
|
|
|
CPAN ID: LUIZBENE |
806
|
|
|
|
|
|
|
Siffra TI |
807
|
|
|
|
|
|
|
luiz@siffra.com.br |
808
|
|
|
|
|
|
|
https://siffra.com.br |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=head1 COPYRIGHT |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
This program is free software; you can redistribute |
813
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
The full text of the license can be found in the |
816
|
|
|
|
|
|
|
LICENSE file included with this module. |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
=head1 SEE ALSO |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
perl(1). |
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
=cut |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
1; |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
830
|
|
|
|
|
|
|
|