[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Net::FTPServer] testing wget with net::ftpserver
From: |
Mauro Tortonesi |
Subject: |
[Net::FTPServer] testing wget with net::ftpserver |
Date: |
Fri, 20 Jan 2006 14:37:43 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050322) |
hi Richard and all,
i am writing a test suite for wget and i am planning to use
Net::FTPServer as a server to test FTP downloads.
what i would like to do is to setup Net::FTPServer::InMem::Server with a
predefined set of resources, which varies from test to test.
so, i've written a simple extension of Net::FTPServer::InMem::Server:
#!/usr/bin/perl -w
package FTPServer;
use strict;
use Net::FTPServer::InMem::Server;
use Net::FTPServer::InMem::FileHandle;
use Net::FTPServer::InMem::DirHandle;
our @ISA = qw(Net::FTPServer::InMem::Server);
my $VERSION = 0.01;
my $urls;
sub authentication_hook {
my $self = shift;
my $user = shift;
my $pass = shift;
my $user_is_anon = shift;
return 0 if $user_is_anon;
return -1;
}
sub root_directory_hook {
my $self = shift;
my $rootdir = Net::FTPServer::InMem::DirHandle->new ($self);
while (my ($filepath, $filedata) = each %{FTPServer::urls}) {
my $currdir = $rootdir;
$filepath =~ s/^\/+//;
my @path = split (/\//, $filepath);
my $filename = $path[-1];
while ($#path > 0) {
my $dir = shift(@path);
$currdir->mkdir($dir) unless $currdir->get($dir);
$currdir = $currdir->get($dir);
}
my $FH = $currdir->open($filename, "r");
print "write file content: |", $filedata->{content}, "|\n";
$FH->print($filedata->{content});
$FH->close();
}
return $rootdir;
}
sub setup_urls {
$FTPServer::urls = shift;
}
1;
which is called by a test script like this one:
#!/usr/bin/perl -w
use strict;
use FTPServer;
my $dummyfile = <<EOF;
Content
EOF
# code, msg, headers, content
my %urls = (
'/dummy.html' => {
content => $dummyfile
},
);
FTPServer::setup_urls(\%urls);
my $the_test = FTPServer->run (['-s', '-p', '8021', '-C',
'anonymous.conf']);
of course, the anonymous.conf file contains "allow anonymous: 1".
unfortunately, i can't get this code to work. the ftp server is
correctly launched but with an empty file system. i haven't found any
example of how to setup an in-memory file system with ftpserver, so
maybe i am doing something wrong?
--
Aequam memento rebus in arduis servare mentem...
Mauro Tortonesi http://www.tortonesi.com
University of Ferrara - Dept. of Eng. http://www.ing.unife.it
GNU Wget - HTTP/FTP file retrieval tool http://www.gnu.org/software/wget
Deep Space 6 - IPv6 for Linux http://www.deepspace6.net
Ferrara Linux User Group http://www.ferrara.linux.it
- [Net::FTPServer] testing wget with net::ftpserver,
Mauro Tortonesi <=