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::InMem::FileHandle - Store files in local memory |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Net::FTPServer::InMem::FileHandle; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package Net::FTPServer::InMem::FileHandle; |
36
|
|
|
|
|
|
|
|
37
|
75
|
|
|
75
|
|
1108
|
use strict; |
|
75
|
|
|
|
|
145
|
|
|
75
|
|
|
|
|
2073
|
|
38
|
|
|
|
|
|
|
|
39
|
75
|
|
|
75
|
|
348
|
use vars qw($VERSION); |
|
75
|
|
|
|
|
141
|
|
|
75
|
|
|
|
|
4677
|
|
40
|
|
|
|
|
|
|
( $VERSION ) = '$Revision: 1.2 $ ' =~ /\$Revision:\s+([^\s]+)/; |
41
|
|
|
|
|
|
|
|
42
|
75
|
|
|
75
|
|
422
|
use Carp qw(croak confess); |
|
75
|
|
|
|
|
227
|
|
|
75
|
|
|
|
|
3157
|
|
43
|
75
|
|
|
75
|
|
385
|
use IO::Scalar; |
|
75
|
|
|
|
|
159
|
|
|
75
|
|
|
|
|
2953
|
|
44
|
|
|
|
|
|
|
|
45
|
75
|
|
|
75
|
|
398
|
use Net::FTPServer::FileHandle; |
|
75
|
|
|
|
|
134
|
|
|
75
|
|
|
|
|
1292
|
|
46
|
75
|
|
|
75
|
|
19551
|
use Net::FTPServer::InMem::DirHandle; |
|
75
|
|
|
|
|
175
|
|
|
75
|
|
|
|
|
2238
|
|
47
|
|
|
|
|
|
|
|
48
|
75
|
|
|
75
|
|
460
|
use vars qw(@ISA); |
|
75
|
|
|
|
|
129
|
|
|
75
|
|
|
|
|
23313
|
|
49
|
|
|
|
|
|
|
@ISA = qw(Net::FTPServer::FileHandle); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Return a new file handle. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new |
54
|
|
|
|
|
|
|
{ |
55
|
131
|
|
|
131
|
1
|
299
|
my $class = shift; |
56
|
131
|
|
|
|
|
221
|
my $ftps = shift; |
57
|
131
|
|
|
|
|
215
|
my $pathname = shift; |
58
|
131
|
|
|
|
|
213
|
my $dir_id = shift; |
59
|
131
|
|
|
|
|
198
|
my $file_id = shift; |
60
|
131
|
|
|
|
|
202
|
my $content = shift; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Create object. |
63
|
131
|
|
|
|
|
597
|
my $self = Net::FTPServer::FileHandle->new ($ftps, $pathname); |
64
|
|
|
|
|
|
|
|
65
|
131
|
|
|
|
|
335
|
$self->{fs_dir_id} = $dir_id; |
66
|
131
|
|
|
|
|
285
|
$self->{fs_file_id} = $file_id; |
67
|
131
|
|
|
|
|
256
|
$self->{fs_content} = $content; |
68
|
|
|
|
|
|
|
|
69
|
131
|
|
|
|
|
537
|
return bless $self, $class; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Return the directory handle for this file. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub dir |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return Net::FTPServer::InMem::DirHandle->new ($self->{ftps}, |
79
|
|
|
|
|
|
|
$self->dirname, |
80
|
0
|
|
|
|
|
0
|
$self->{fs_dir_id}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Open the file handle. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub open |
86
|
|
|
|
|
|
|
{ |
87
|
51
|
|
|
51
|
1
|
112
|
my $self = shift; |
88
|
51
|
|
|
|
|
97
|
my $mode = shift; |
89
|
|
|
|
|
|
|
|
90
|
51
|
50
|
|
|
|
135
|
if ($mode eq "r") # Open file for reading. |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
91
|
|
|
|
|
|
|
{ |
92
|
51
|
|
|
|
|
361
|
return new IO::Scalar ($self->{fs_content}); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ($mode eq "w") # Create/overwrite the file. |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
0
|
return new IO::Scalar ($self->{fs_content}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
elsif ($mode eq "a") # Append to the file. |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
|
|
0
|
return new IO::Scalar ($self->{fs_content}); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
|
|
0
|
croak "unknown file mode: $mode; use 'r', 'w' or 'a' instead"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub status |
109
|
|
|
|
|
|
|
{ |
110
|
65
|
|
|
65
|
1
|
125
|
my $self = shift; |
111
|
65
|
|
|
|
|
196
|
my $username = substr $self->{ftps}{user}, 0, 8; |
112
|
|
|
|
|
|
|
|
113
|
65
|
|
|
|
|
112
|
my $size = length $ { $self->{fs_content} }; |
|
65
|
|
|
|
|
185
|
|
114
|
|
|
|
|
|
|
|
115
|
65
|
|
|
|
|
317
|
return ( 'f', 0644, 1, $username, "users", $size, 0 ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Move a file to elsewhere. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub move |
121
|
|
|
|
|
|
|
{ |
122
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
123
|
1
|
|
|
|
|
4
|
my $dirh = shift; |
124
|
1
|
|
|
|
|
3
|
my $filename = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$Net::FTPServer::InMem::DirHandle::files{$self->{fs_file_id}}{dir_id} |
127
|
1
|
|
|
|
|
4
|
= $dirh->{fs_dir_id}; |
128
|
|
|
|
|
|
|
$Net::FTPServer::InMem::DirHandle::files{$self->{fs_file_id}}{name} |
129
|
1
|
|
|
|
|
4
|
= $filename; |
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
|
|
7
|
return 0; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Delete a file. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub delete |
137
|
|
|
|
|
|
|
{ |
138
|
9
|
|
|
9
|
1
|
15
|
my $self = shift; |
139
|
|
|
|
|
|
|
|
140
|
9
|
|
|
|
|
32
|
delete $Net::FTPServer::InMem::DirHandle::files{$self->{fs_file_id}}; |
141
|
|
|
|
|
|
|
|
142
|
9
|
|
|
|
|
23
|
return 0; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1 # So that the require or use succeeds. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |