AnyEvent-FTP
view release on metacpan or search on metacpan
t/anyevent_ftp_client.t view on Meta::CPAN
unlink $fn;
ok !-e $fn, 'remote file deleted';
$client->quit->recv;
};
}
};
subtest 'login' => sub {
reset_timeout;
my $client = eval { AnyEvent::FTP::Client->new };
diag $@ if $@;
isa_ok $client, 'AnyEvent::FTP::Client';
prep_client( $client );
our $config;
$client->connect($config->{host}, $config->{port})->recv;
my $res = eval { $client->login($config->{user}, $config->{pass})->recv };
diag $@ if $@;
isa_ok $res, 'AnyEvent::FTP::Response';
is $res->code, 230, 'code = 230';
is eval { $client->quit->recv->code }, 221, 'code = 221';
diag $@ if $@;
$client->connect($config->{host}, $config->{port})->recv;
eval { $client->login('bogus', 'bogus')->recv };
my $error = $@;
isa_ok $error, 'AnyEvent::FTP::Response';
is $error->code, 530, 'code = 530';
eval { $client->quit->recv };
};
subtest 'uri' => sub {
reset_timeout;
skip_all 'requires client and server on localhost' if $ENV{AEF_REMOTE};
skip_all 'requires URI' unless eval q{ require URI };
my $client = eval { AnyEvent::FTP::Client->new };
diag $@ if $@;
isa_ok $client, 'AnyEvent::FTP::Client';
our $config;
our $detect;
local $config->{dir} = $CWD;
prep_client( $client );
my $uri = URI->new('ftp:');
$uri->host($config->{host});
$uri->port($config->{port});
$uri->user($config->{user});
$uri->password($config->{pass});
$uri->path(do {
my $dir = $config->{dir};
if($^O eq 'MSWin32')
{
(undef,$dir,undef) = File::Spec->splitpath($dir,1);
$dir =~ s{\\}{/}g;
}
$dir;
});
isa_ok $uri, 'URI';
subtest 'test with real URI object' => sub {
my $res = eval { $client->connect($uri)->recv };
is $@, '';
if($@ ne '')
{
eval { $client->quit->recv };
return;
}
isa_ok $res, 'AnyEvent::FTP::Response';
is $res->code, 250, 'code = 250';
is $client->pwd->recv, net_pwd($config->{dir}), "dir = " . net_pwd($config->{dir});
$client->quit->recv;
};
subtest 'test with string URI' => sub {
my $res = eval { $client->connect($uri->as_string)->recv };
is $@, '';
if($@ ne '')
{
eval { $client->quit->recv };
return;
}
isa_ok $res, 'AnyEvent::FTP::Response';
is $res->code, 250, 'code = 250';
is $client->pwd->recv, net_pwd($config->{dir}), "dir = " . net_pwd($config->{dir});
$client->quit->recv;
};
$uri->user('bogus');
$uri->password('bogus');
SKIP: {
skip 'bftp quit broken', 2 if $detect->{xb};
eval { $client->connect($uri->as_string)->recv };
my $error = $@;
isa_ok $error, 'AnyEvent::FTP::Response';
is $error->code, 530, 'code = 530';
$client->quit->recv;
};
$uri->user($config->{user});
$uri->password($config->{pass});
$uri->path('/bogus/bogus/bogus');
SKIP: {
skip 'bftp quit broken', 2 if $detect->{xb};
eval { $client->connect($uri->as_string)->recv };
my $error = $@;
isa_ok $error, 'AnyEvent::FTP::Response';
is $error->code, 550, 'code = 550';
$client->quit->recv;
};
};
subtest 'rest' => sub {
reset_timeout;
skip_all 'requires client and server on localhost' if $ENV{AEF_REMOTE};
our $config;
$config->{dir} = tempdir( CLEANUP => 1 );
my $fn = File::Spec->catfile($config->{dir}, 'foo.txt');
do {
open my $fh, '>', $fn;
print $fh "012345678901234567890";
close $fh;
};
foreach my $passive (0,1)
{
my $client = AnyEvent::FTP::Client->new( passive => $passive );
prep_client( $client );
$client->connect($config->{host}, $config->{port})->recv;
$client->login($config->{user}, $config->{pass})->recv;
$client->type('I')->recv;
$client->cwd($config->{dir})->recv;
do {
my $data = '0123456789';
my $ret1 = eval { $client->rest(10)->recv; };
diag $@ if $@;
isa_ok $ret1, 'AnyEvent::FTP::Response';
my $ret2 = eval { $client->retr('foo.txt', sub { $data .= shift }, restart => length $data)->recv; };
diag $@ if $@;
isa_ok $ret2, 'AnyEvent::FTP::Response';
is $data, "012345678901234567890", 'data = "012345678901234567890"';
};
$client->quit->recv;
}
};
subtest 'connect' => sub {
reset_timeout;
my $done = AnyEvent->condvar;
my $client = eval { AnyEvent::FTP::Client->new };
diag $@ if $@;
( run in 2.696 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )