Test::FTP::Server - ftpd runner for tests
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;
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.
Test::FTP::Server
Net::FTPServer
Create a ftpd instance.
%options
users
Definition of users.
user and pass are used for login.
user
pass
If root is specified, ftpd behaves as if the specified directory is the root directory.
root
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.
sandbox
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 a ftpd instance.
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); }, );
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.
Taku Amano <taku@toi-planning.net>
Kazuhiro Osawa
Roy Storey
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::FTP::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::FTP::Server
CPAN shell
perl -MCPAN -e shell install Test::FTP::Server
For more information on module installation, please visit the detailed CPAN module installation guide.