File Coverage

blib/lib/Net/FTPServer/InMem/Server.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 4 100.0
condition 2 3 66.6
subroutine 11 11 100.0
pod 4 4 100.0
total 53 54 98.1


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::Server - Store files in local memory
26              
27             =head1 SYNOPSIS
28              
29             inmem-ftpd.pl [-d] [-v] [-p port] [-s] [-S] [-V] [-C conf_file]
30              
31             =head1 DESCRIPTION
32              
33             C is the example FTP server
34             personality. This personality implements a simple
35             FTP server which stores files in local memory. This personality
36             is used mainly for automatic testing in the test suites (see the
37             C directory in the distribution).
38              
39             =head1 METHODS
40              
41             =cut
42              
43             package Net::FTPServer::InMem::Server;
44              
45 75     75   4644958 use strict;
  75         781  
  75         2181  
46              
47 75     75   383 use vars qw($VERSION);
  75         130  
  75         5282  
48             ( $VERSION ) = '$Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/;
49              
50 75     75   73253 use Net::FTPServer;
  75         208  
  75         2448  
51 75     75   20496 use Net::FTPServer::InMem::FileHandle;
  75         173  
  75         1813  
52 75     75   442 use Net::FTPServer::InMem::DirHandle;
  75         139  
  75         1313  
53              
54 75     75   329 use vars qw(@ISA);
  75         121  
  75         2991  
55             @ISA = qw(Net::FTPServer);
56              
57             # Variables.
58 75     75   363 use vars qw(%users);
  75         134  
  75         11737  
59              
60             $users{rich} = '123456';
61             $users{rob} = '123456';
62              
63             # This is called before configuration.
64              
65             sub pre_configuration_hook
66             {
67 41     41 1 152 my $self = shift;
68              
69 41         267 $self->{version_string} .= " Net::FTPServer::InMem/$VERSION";
70             }
71              
72             # Perform login against the database.
73              
74             sub authentication_hook
75             {
76 24     24 1 77 my $self = shift;
77 24         67 my $user = shift;
78 24         59 my $pass = shift;
79 24         76 my $user_is_anon = shift;
80              
81             # Allow anonymous access.
82 24 100       122 return 0 if $user_is_anon;
83              
84             # Verify access against our short list of username/password combinations.
85 19 100 66     309 return 0 if exists $users{$user} && $users{$user} eq $pass;
86              
87             # Unsuccessful login.
88 1         21 return -1;
89             }
90              
91             # Called just after user C<$user> has successfully logged in.
92              
93             sub user_login_hook
94       23 1   {
95             # Override the default by doing nothing.
96             }
97              
98             # Return an instance of Net::FTPServer::InMem::DirHandle
99             # corresponding to the root directory.
100              
101             sub root_directory_hook
102             {
103 47     47 1 103 my $self = shift;
104              
105 47         536 return new Net::FTPServer::InMem::DirHandle ($self);
106             }
107              
108             1 # So that the require or use succeeds.
109              
110             __END__