| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Net::FTPServer A Perl FTP Server |
|
4
|
|
|
|
|
|
|
# Copyright (C) 2000 Bibliotech Ltd., Unit 2-3, 50 Carnwath Road, |
|
5
|
|
|
|
|
|
|
# London, SW6 3EG, United Kingdom. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
8
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
9
|
|
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
|
10
|
|
|
|
|
|
|
# (at your option) any later version. |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
13
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
18
|
|
|
|
|
|
|
# along with this program; if not, write to the Free Software |
|
19
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=pod |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Net::FTPServer::RO::FileHandle - The anonymous, read-only FTP server personality |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Net::FTPServer::RO::FileHandle; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package Net::FTPServer::RO::FileHandle; |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
633
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
55
|
|
|
40
|
|
|
|
|
|
|
( $VERSION ) = '$Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/; |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
5
|
use Net::FTPServer::FileHandle; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
17
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
4
|
use vars qw(@ISA); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
280
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
@ISA = qw(Net::FTPServer::FileHandle); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item $dirh = $fileh->dir; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Return the directory which contains this file. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub dir |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $dirname = $self->{_pathname}; |
|
63
|
0
|
|
|
|
|
|
$dirname =~ s,[^/]+$,,; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return Net::FTPServer::RO::DirHandle->new ($self->{ftps}, $dirname); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item $fh = $fileh->open (["r"|"w"|"a"]); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Open a file handle (derived from C, see |
|
73
|
|
|
|
|
|
|
C) in either read or write mode. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub open |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
80
|
0
|
|
|
|
|
|
my $mode = shift; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
return undef unless $mode eq "r"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return new IO::File $self->{_pathname}, $mode; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item ($mode, $perms, $nlink, $user, $group, $size, $time) = $handle->status; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Return the file or directory status. The fields returned are: |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$mode Mode 'd' = directory, |
|
94
|
|
|
|
|
|
|
'f' = file, |
|
95
|
|
|
|
|
|
|
and others as with |
|
96
|
|
|
|
|
|
|
the find(1) -type option. |
|
97
|
|
|
|
|
|
|
$perms Permissions Permissions in normal octal numeric format. |
|
98
|
|
|
|
|
|
|
$nlink Link count |
|
99
|
|
|
|
|
|
|
$user Username In printable format. |
|
100
|
|
|
|
|
|
|
$group Group name In printable format. |
|
101
|
|
|
|
|
|
|
$size Size File size in bytes. |
|
102
|
|
|
|
|
|
|
$time Time Time (usually mtime) in Unix time_t format. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
In derived classes, some of this status information may well be |
|
105
|
|
|
|
|
|
|
synthesized, since virtual filesystems will often not contain |
|
106
|
|
|
|
|
|
|
information in a Unix-like format. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub status |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, |
|
115
|
|
|
|
|
|
|
$atime, $mtime, $ctime, $blksize, $blocks) |
|
116
|
0
|
|
|
|
|
|
= lstat $self->{_pathname}; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# If the file has been removed since we created this |
|
119
|
|
|
|
|
|
|
# handle, then $dev will be undefined. Return dummy status |
|
120
|
|
|
|
|
|
|
# information. |
|
121
|
0
|
0
|
|
|
|
|
return ("f", 0000, 1, "-", "-", 0, 0) unless defined $dev; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# Generate printable user/group. |
|
124
|
0
|
|
0
|
|
|
|
my $user = getpwuid ($uid) || "-"; |
|
125
|
0
|
|
0
|
|
|
|
my $group = getgrgid ($gid) || "-"; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Permissions from mode. |
|
128
|
0
|
|
|
|
|
|
my $perms = $mode & 0777; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Work out the mode using special "_" operator which causes Perl |
|
131
|
|
|
|
|
|
|
# to use the result of the previous stat call. |
|
132
|
0
|
0
|
|
|
|
|
$mode |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
= (-f _ ? 'f' : |
|
134
|
|
|
|
|
|
|
(-d _ ? 'd' : |
|
135
|
|
|
|
|
|
|
(-l _ ? 'l' : |
|
136
|
|
|
|
|
|
|
(-p _ ? 'p' : |
|
137
|
|
|
|
|
|
|
(-S _ ? 's' : |
|
138
|
|
|
|
|
|
|
(-b _ ? 'b' : |
|
139
|
|
|
|
|
|
|
(-c _ ? 'c' : '?'))))))); |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return ($mode, $perms, $nlink, $user, $group, $size, $mtime); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item $rv = $handle->move ($dirh, $filename); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Move the current file (or directory) into directory C<$dirh> and |
|
149
|
|
|
|
|
|
|
call it C<$filename>. If the operation is successful, return 0, |
|
150
|
|
|
|
|
|
|
else return -1. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Underlying filesystems may impose limitations on moves: for example, |
|
153
|
|
|
|
|
|
|
it may not be possible to move a directory; it may not be possible |
|
154
|
|
|
|
|
|
|
to move a file to another directory; it may not be possible to |
|
155
|
|
|
|
|
|
|
move a file across filesystems. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub move |
|
160
|
|
|
|
|
|
|
{ |
|
161
|
0
|
|
|
0
|
1
|
|
return -1; # Not permitted in read-only server. |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=pod |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item $rv = $fileh->delete; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Delete the current file. If the delete command was |
|
169
|
|
|
|
|
|
|
successful, then return 0, else if there was an error return -1. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub delete |
|
174
|
|
|
|
|
|
|
{ |
|
175
|
0
|
|
|
0
|
1
|
|
return -1; # Not permitted in read-only server. |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item $link = $fileh->readlink; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
If the current file is really a symbolic link, read the contents |
|
181
|
|
|
|
|
|
|
of the link and return it. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub readlink |
|
186
|
|
|
|
|
|
|
{ |
|
187
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
188
|
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
return readlink $self->{_pathname}; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1 # So that the require or use succeeds. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
__END__ |