line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2011 Daneel S. Yaitskov . |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# All rights reserved. |
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
5
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Net::FTPTurboSync; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
26030
|
use 5.010001; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
43
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
37
|
|
12
|
1
|
|
|
1
|
|
5
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
89
|
|
13
|
1
|
|
|
1
|
|
6
|
use File::Find; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
14
|
1
|
|
|
1
|
|
687
|
use Net::FTPTurboSync::PrgOpts; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
15
|
1
|
|
|
1
|
|
694
|
use Net::FTPTurboSync::LocalFile; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
29
|
|
16
|
1
|
|
|
1
|
|
451
|
use Net::FTPTurboSync::LocalDir; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
17
|
1
|
|
|
1
|
|
472
|
use Net::FTPTurboSync::RemoteDir; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
18
|
1
|
|
|
1
|
|
533
|
use Net::FTPTurboSync::RemoteFile; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
783
|
|
19
|
|
|
|
|
|
|
require Exporter; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
24
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
25
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# This allows declaration use Net::FTPTurboSync ':all'; |
28
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
29
|
|
|
|
|
|
|
# will save memory. |
30
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our @EXPORT = qw(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub theOpts { |
39
|
0
|
|
|
0
|
0
|
|
return $Net::FTPTurboSync::PrgOpts::theOpts; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $theOpts = $Net::FTPTurboSync::PrgOpts::theOpts; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Net::FTPTurboSync - Perl extension for turbo-ftp-sync script |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Blah blah blah. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 EXPORT |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
None by default. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item B() |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
class - name of this module |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
It build two hashes of all directories and all files including nested and |
65
|
|
|
|
|
|
|
returns an array of hash references to them, respectively. Hashes' key is a |
66
|
|
|
|
|
|
|
relative path to file or folder from current folder. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub buildlocaltree () { |
71
|
0
|
|
|
0
|
1
|
|
my ($class) = @_; |
72
|
0
|
|
|
|
|
|
my %ldirs = (); |
73
|
0
|
|
|
|
|
|
my %lfiles = (); |
74
|
0
|
|
|
|
|
|
chdir theOpts()->{localdir}; |
75
|
0
|
|
|
|
|
|
my $ldl = length(Cwd::getcwd()); |
76
|
0
|
0
|
|
|
|
|
if ($theOpts->{doflat}) { |
77
|
0
|
|
|
|
|
|
my @globbed=glob("{*,.*}"); |
78
|
0
|
|
|
|
|
|
foreach my $curglobbed (@globbed) { |
79
|
0
|
0
|
|
|
|
|
next if (! -f $curglobbed); |
80
|
0
|
|
|
|
|
|
$lfiles{$curglobbed} = Net::FTPTurboSync::LocalFile->load ( $curglobbed ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} else { |
83
|
0
|
|
|
0
|
|
|
find ( { wanted=> sub { noticelocalfile ( $File::Find::name, |
84
|
|
|
|
|
|
|
\%ldirs, |
85
|
|
|
|
|
|
|
\%lfiles, $ldl ) ; }, |
86
|
0
|
|
|
|
|
|
follow_fast => $theOpts->{followsymlinks}, |
87
|
|
|
|
|
|
|
no_chdir => 1 |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Cwd::getcwd()."/" |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
return ( \%ldirs, \%lfiles ); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub noticelocalfile { |
96
|
0
|
|
|
0
|
0
|
|
my ( $fileName, $ldirs, $lfiles, $ldl ) = @_; |
97
|
0
|
|
|
|
|
|
my $relfilename = substr( $fileName, $ldl ); |
98
|
0
|
|
|
|
|
|
$relfilename =~ s!^/!!; |
99
|
0
|
0
|
|
|
|
|
if (length($relfilename) == 0) { return; } |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $theOpts = theOpts(); |
101
|
0
|
0
|
|
|
|
|
if (theOpts()->{ignoremask} ne "") { |
102
|
0
|
0
|
|
|
|
|
if ($relfilename =~ /$theOpts->{ignoremask}/ ) { |
103
|
0
|
0
|
|
|
|
|
if ($theOpts->{doverbose}) { |
104
|
0
|
|
|
|
|
|
print "Ignoring $relfilename which matches $theOpts->{ignoremask}\n"; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
0
|
0
|
|
|
|
|
if (-d $_) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$ldirs->{$relfilename} = Net::FTPTurboSync::LocalDir->load ( $relfilename ); |
111
|
|
|
|
|
|
|
}elsif (-f $_) { |
112
|
0
|
|
|
|
|
|
$lfiles->{$relfilename} = Net::FTPTurboSync::LocalFile->load ( $relfilename ); |
113
|
|
|
|
|
|
|
}elsif (-l $_) { |
114
|
0
|
|
|
|
|
|
print "Link isn't supported: $fileName\n"; |
115
|
|
|
|
|
|
|
}elsif (! $theOpts->{doquiet}) { |
116
|
0
|
|
|
|
|
|
print "Ignoring file of unknown type: $fileName\n"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B($ftp,$dbh) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
class - name of this module |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
ftp - object Net::FTPTurboSync::MyFtp |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
dbh - database handle which is returned from DBI->connect(...) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The method returns an array with two elements. First is a hash ref of |
130
|
|
|
|
|
|
|
directories found in current folder on FTP server. Second is a hash ref o files |
131
|
|
|
|
|
|
|
found in current folder on FTP server. A hask key of both hashes is an absolute |
132
|
|
|
|
|
|
|
path. A hash value of first hash is RemoteDir object and a second one is |
133
|
|
|
|
|
|
|
RemoteFile object. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The method gets data from the database object rather than ftp. Ftp object is |
136
|
|
|
|
|
|
|
passed for futher using. |
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub buildremotetree() { |
140
|
0
|
|
|
0
|
1
|
|
my ( $class, $ftp, $dbh ) = @_; |
141
|
0
|
|
|
|
|
|
my %rdirs = (); |
142
|
0
|
|
|
|
|
|
my %rfiles = (); |
143
|
0
|
|
|
|
|
|
my $dirs = $dbh->selectAllDirs(); |
144
|
0
|
|
|
|
|
|
foreach my $dir ( @$dirs ){ |
145
|
0
|
|
|
|
|
|
$rdirs{ $dir->{fullname} } = Net::FTPTurboSync::RemoteDir->load ( $ftp, $dbh, $dir ) ; |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
my $files = $dbh->selectAllFiles(); |
148
|
0
|
|
|
|
|
|
foreach my $file ( @$files ){ |
149
|
0
|
|
|
|
|
|
$rfiles{ $file->{fullname} } = Net::FTPTurboSync::RemoteFile->load( $ftp, $dbh, $file ); |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
return ( \%rdirs, \%rfiles ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item B($dbh,$ldir,$lfiles) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
class - name of this module |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
dbh - database handle object |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
ldir - a hash ref of directories to be written in db |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
lfiles - a hash ref of files to be written in db |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub fillDb { |
167
|
0
|
|
|
0
|
1
|
|
my ($class, $dbh, $ldirs, $lfiles) = @_; |
168
|
0
|
|
|
|
|
|
foreach my $lfile (values(%$lfiles)) { |
169
|
0
|
|
|
|
|
|
$dbh->uploadFile( $lfile->getPath, |
170
|
|
|
|
|
|
|
$lfile->getPerms, |
171
|
|
|
|
|
|
|
$lfile->getModDate, |
172
|
|
|
|
|
|
|
$lfile->getSize ); |
173
|
|
|
|
|
|
|
} |
174
|
0
|
|
|
|
|
|
foreach my $ldir ( values ( %$ldirs ) ) { |
175
|
0
|
|
|
|
|
|
$dbh->createDir( $ldir->getPath, $ldir->getPerms ); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
180
|
|
|
|
|
|
|
__END__ |