AnyEvent-FTP

 view release on metacpan or  search on metacpan

bin/aeftpd  view on Meta::CPAN


my $server = AnyEvent::FTP::Server->new(
  hostname        => $host,
  port            => $port,
  inet            => $inet,
  default_context => $default_context,
);

unless($inet)
{
  $server->on_bind(sub {
    my $uri = URI->new('ftp:');
    $uri->host($host // 'localhost');
    $uri->port(shift);
    $uri->userinfo(join ':', $cred->{user}, $cred->{pass})
      if defined $cred;
    say $uri;
  });
}

if($verbose)

lib/AnyEvent/FTP/Server.pm  view on Meta::CPAN

use Socket qw( unpack_sockaddr_in inet_ntoa );

# ABSTRACT: Simple asynchronous ftp server
our $VERSION = '0.20'; # VERSION


$AnyEvent::FTP::Server::VERSION //= 'dev';

with 'AnyEvent::FTP::Role::Event';

__PACKAGE__->define_events(qw( bind connect ));


has hostname => (
  is       => 'ro',
);


has port => (
  is      => 'ro',
  default => sub { 21 },

lib/AnyEvent/FTP/Server.pm  view on Meta::CPAN

  default => sub { 'AnyEvent::FTP::Server::Context::FSRW' },
);


has welcome => (
  is      => 'ro',
  default => sub { [ 220 => "aeftpd $AnyEvent::FTP::Server::VERSION" ] },
);


has bindport => (
  is => 'rw',
);


has inet => (
  is      => 'ro',
  default => sub { 0 },
);

sub BUILD

lib/AnyEvent/FTP/Server.pm  view on Meta::CPAN


  $self;
}

sub _start_standalone
{
  my($self) = @_;

  my $prepare = sub {
    my($fh, $host, $port) = @_;
    $self->bindport($port);
    $self->emit(bind => $port);
  };

  my $connect = sub {
    my($fh, $host, $port) = @_;

    my $con = AnyEvent::FTP::Server::Connection->new(
      context => $self->{default_context}->new,
      ip => do {
        my($port, $addr) = unpack_sockaddr_in getsockname $fh;
        inet_ntoa $addr;

lib/AnyEvent/FTP/Server.pm  view on Meta::CPAN

Readonly: the default context class (can be set as a parameter in the
constructor).

=head2 welcome

 my($code, $message) = @{ $server->welcome };

The welcome messages as key value pairs. Read only and can be overridden by
the constructor.

=head2 bindport

 my $port = $server->bindport;
 $server->bindport($port);

Retrieves or sets the TCP port to bind to.

=head2 inet

 my $bool = $server->inet;

Readonly (assignable via the constructor). If true, then assume a TCP
connection has been established by inet. The default (false) is to start
a standalone server.

=head1 METHODS

lib/Test/AnyEventFTPServer.pm  view on Meta::CPAN

      shift->context->authenticator(sub {
        return $_[0] eq $user && $_[1] eq $pass;
      });
    });

    my $cv = AnyEvent->condvar;
    my $timer = AnyEvent->timer(
      after => 5,
      cb    => sub { $cv->croak("timeout creating ftp server") },
    );
    $server->on_bind(sub {
      $uri->port(shift);
      $cv->send;
    });
    $server->start;
    $cv->recv;
  };
  my $error = $@;

  $message //= "created FTP ($name) server at $uri";

t/lib/Test2/Tools/ClientTests.pm  view on Meta::CPAN


  $config->{host} = 'localhost';
  $config->{user} = join '', map { chr(ord('a') + int rand(26)) } (1..10);
  $config->{pass} = join '', map { chr(ord('a') + int rand(26)) } (1..10);
  {
    my $ctx = context();
    $ctx->note("using fake credentials ", join ':', $config->{user}, $config->{pass});
    $ctx->release;
  }

  $server->on_bind(sub {
    my $port = shift;
    $config->{port} = $port;
    my $ctx = context();
    $ctx->note("binding aeftpd localhost:$port");
    $ctx->release;
  });

  $server->on_connect(sub {
    my $con = shift;
    $con->context->authenticator(sub {
      my($user, $pass) = @_;
      $user eq $config->{user} && $pass eq $config->{pass} ? 1 : 0;
    });
    $con->context->bad_authentication_delay(0);



( run in 0.787 second using v1.01-cache-2.11-cpan-e93a5daba3e )