forked from usualoma/p5-test-ftp-server
/
README
134 lines (106 loc) · 3.17 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
NAME
Test::FTP::Server - ftpd runner for tests
SYNOPSIS
use Test::TCP;
use Test::FTP::Server;
my $user = 'testuser';
my $pass = 'testpass';
my $root_directory = '/path/to/root_directory';
my $server = Test::FTP::Server->new(
'users' => [{
'user' => $user,
'pass' => $pass,
'root' => $root_directory,
}],
'ftpd_conf' => {
'port' => $port,
'daemon mode' => 1,
'run in background' => 0,
},
);
$server->run;
or
use Test::TCP;
use Test::FTP::Server;
my $user = 'testuser';
my $pass = 'testpass';
my $sandbox_base = '/path/to/sandbox_base';
my $server = Test::FTP::Server->new(
'users' => [{
'user' => $user,
'pass' => $pass,
'sandbox' => $sandbox_base,
}],
'ftpd_conf' => {
'port' => $port,
'daemon mode' => 1,
'run in background' => 0,
},
);
$server->run;
DESCRIPTION
"Test::FTP::Server" run "Net::FTPServer" internally. The server's
settings can be specified as a parameter, therefore it is not necessary
to prepare the configuration file.
FUNCTIONS
new
Create a ftpd instance.
%options
"users"
Definition of users.
"user" and "pass" are used for login.
If "root" is specified, ftpd behaves as if the specified directory is
the root directory.
If "sandbox" is specified, The content of sandbox is copied into the
temporary directory, and ftpd behaves as if the temporary directory
is the root directory. The content of sandbox never changes by the
user's operation.
It is necessary to specify "root" or "sandbox".
"ftpd_conf"
The settings that is usually specified in "/etc/ftpd.conf" when using
Net::FTPServer.
Specified by the hash reference.
run
Run a ftpd instance.
EXAMPLE
use Test::FTP::Server;
use Test::TCP;
use Net::FTP;
my $user = 'testid';
my $pass = 'testpass';
my $sandbox_base = '/path/to/sandbox_base';
test_tcp(
server => sub {
my $port = shift;
Test::FTP::Server->new(
'users' => [{
'user' => $user,
'pass' => $pass,
'sandbox' => $sandbox_base,
}],
'ftpd_conf' => {
'port' => $port,
'daemon mode' => 1,
'run in background' => 0,
},
)->run;
},
client => sub {
my $port = shift;
my $ftp = Net::FTP->new('localhost', Port => $port);
ok($ftp);
ok($ftp->login($user, $pass));
ok($ftp->quit);
},
);
NOTES
* Test::FTP::Server is for test use only. "root" and "sandbox" is not
using chroot to keep available for any user. Therefore, there is a
security risk when a server opened to the public.
AUTHOR
Taku Amano <taku@toi-planning.net>
SEE ALSO
Net::FTPServer
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.