AnyEvent-FTP

 view release on metacpan or  search on metacpan

LICENSE  view on Meta::CPAN

changed that file, and provided that you do at least ONE of the following:

  a) place your modifications in the Public Domain or otherwise make them
     Freely Available, such as by posting said modifications to Usenet or an
     equivalent medium, or placing the modifications on a major archive site
     such as ftp.uu.net, or by allowing the Copyright Holder to include your
     modifications in the Standard Version of the Package.

  b) use the modified Package only within your corporation or organization.

  c) rename any non-standard executables so the names do not conflict with
     standard executables, which must also be provided, and provide a separate
     manual page for each non-standard executable that clearly documents how it
     differs from the Standard Version.

  d) make other distribution arrangements with the Copyright Holder.

4. You may distribute the programs of this Package in object code or executable
form, provided that you do at least ONE of the following:

  a) distribute a Standard Version of the executables and library files,

MANIFEST  view on Meta::CPAN

t/anyevent_ftp_server_context_fsrw__ascii.t
t/anyevent_ftp_server_context_fsrw__help_coverage.t
t/anyevent_ftp_server_context_fsrw__unauth.t
t/anyevent_ftp_server_context_memory__cdup.t
t/anyevent_ftp_server_context_memory__cwd.t
t/anyevent_ftp_server_context_memory__dele.t
t/anyevent_ftp_server_context_memory__help_coverage.t
t/anyevent_ftp_server_context_memory__mkd.t
t/anyevent_ftp_server_context_memory__nlst.t
t/anyevent_ftp_server_context_memory__pwd.t
t/anyevent_ftp_server_context_memory__rename.t
t/anyevent_ftp_server_context_memory__rmd.t
t/anyevent_ftp_server_context_memory__size.t
t/anyevent_ftp_server_context_memory__stat.t
t/anyevent_ftp_server_role_auth.t
t/anyevent_ftp_server_role_help.t
t/anyevent_ftp_server_role_old.t
t/anyevent_ftp_server_role_transferprep.t
t/anyevent_ftp_server_role_type.t
t/anyevent_ftp_server_unambiguousresponseencoder.t
t/lib/Test2/Tools/ClientTests.pm

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

}


sub nlst
{
  my($self, $location) = @_;
  $self->list($location, 'NLST');
}


sub rename
{
  my($self, $from, $to) = @_;
  $self->push_command(
    [ RNFR => $from ],
    [ RNTO => $to   ],
  );
}


sub pwd

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

 
 $cv->recv;

=head2 nlst

 $client->nlst($location);

Works exactly like the C<list> method, except the FTP C<NLST> command is used.
The main difference is that this method returns filenames only.

=head2 rename

 $client->rename($from, $to);

This method renames the remote file from C<$from> to C<$to>.
It uses the FTP C<RNFR> and C<RNTO> commands and thus this:

 my $cv = $client->rename($from, $to);

is a short cut for:

 my $cv;
 $client->rnfr($from)->cb(sub {
   $cv = $client->rnto($to);
 });

Although C<$cv> may not be defined right away, so use the second with care.

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

=head2 dele

 $client->dele( $path );

Delete the file on the remote server.

=head2 rnfr

 $client->rnfr;

Specify the old name for renaming a file.  See C<rename> method for a shortcut.

=head2 rnto

 $client->rnto;

Specify the new name for renaming a file.  See C<rename> method for a shortcut.

=head2 noop

 $client->noop;

Don't do anything.  The server will send an OK reply.

=head2 allo

 $client->allo( $size );

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



sub cwd
{
  my($self, $value) = @_;
  $self->{cwd} = $value if defined $value;
  $self->{cwd} //= '/';
}


sub rename_from
{
  my($self, $value) = @_;
  $self->{rename_from} = $value if defined $value;
  $self->{rename_from};
}


sub help_cwd { 'CWD <sp> pathname' }

sub cmd_cwd
{
  my($self, $con, $req) = @_;

  my $dir = $req->args;

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

  if($path)
  {
    eval {
      local $CWD = $self->cwd;
      if(!-e $path)
      {
        $con->send_response(550 => 'No such file or directory');
      }
      elsif(-w $path)
      {
        $self->rename_from($path);
        $con->send_response(350 => 'File or directory exists, ready for destination name');
      }
      else
      {
        $con->send_response(550 => 'Permission denied');
      }
    };
    if(my $error = $@)
    {
      warn $error;

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



sub help_rnto { 'RNTO <sp> pathname' }

sub cmd_rnto
{
  my($self, $con, $req) = @_;

  my $path = $req->args;

  if(! defined $self->rename_from)
  {
    $con->send_response(503 => 'Bad sequence of commands');
  }
  elsif(!$path)
  {
    $con->send_response(501 => 'Invalid number of arguments');
  }
  else
  {
    eval {
      local $CWD = $self->cwd;
      if(! -e $path)
      {
        rename $self->rename_from, $path;
        $con->send_response(250 => 'Rename successful');
      }
      else
      {
        $con->send_response(550 => 'File already exists');
      }
    };
    if(my $error = $@)
    {
      warn $error;

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

=back

=head1 ATTRIBUTES

=head2 cwd

 my $dir = $context->cwd;

The current working directory as a string.

=head2 rename_from

 my $filename = $context-E<gt>rename_from;

The filename specified by the last FTP C<RNFR> command.

=head1 COMMANDS

In addition to the commands provided by the above roles,
this context provides these FTP commands:

=over 4

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

    }
  }

  if(exists $store->{$top})
  { return $store->{$top} }
  else
  { return }
}


sub rename_from
{
  my($self, $value) = @_;
  $self->{rename_from} = $value if defined $value;
  $self->{rename_from};
}


sub help_cwd { 'CWD <sp> pathname' }

sub cmd_cwd
{
  my($self, $con, $req) = @_;

  my $dir = Path::Class::Dir->new_foreign('Unix', $req->args)->cleanup;

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

sub cmd_rnfr
{
  my($self, $con, $req) = @_;

  my $path = Path::Class::File->new_foreign('Unix', $req->args);
  my $dir = $self->find($path->parent);
  if(ref($dir) eq 'HASH')
  {
    if(exists $dir->{$path->basename})
    {
      $self->rename_from([$dir,$path->basename]);
      $con->send_response(350 => 'File or directory exists, ready for destination name');
    }
    else
    {
      $con->send_response(550 => 'No such file or directory');
    }
  }
  else
  {
    $con->send_response(550 => 'No such file or directory');

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

  $self->done;
}


sub help_rnto { 'RNTO <sp> pathname' }

sub cmd_rnto
{
  my($self, $con, $req) = @_;

  my $from = $self->rename_from;

  unless(defined $from)
  {
    $con->send_response(503 => 'Bad sequence of commands');
    $self->done;
    return;
  }

  my $path = Path::Class::File->new_foreign('Unix', $req->args);
  my $dir = $self->find($path->parent);

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

=head2 cwd

The current working directory for the context.  This
will be an L<Path::Class::Dir>.

=head2 find

Returns the hash (for directory) or scalar (for file) of
a file in the filesystem.

=head2 rename_from

 my $filename = $context->rename_from;

The filename specified by the last FTP C<RNFR> command.

=head1 COMMANDS

In addition to the commands provided by the above roles,
this context provides these FTP commands:

=over 4

t/anyevent_ftp_client.t  view on Meta::CPAN

    };

    isa_ok $client->appe('foo.txt', \"line 2\n")->recv, 'AnyEvent::FTP::Response';

    do {
      my $data = '';
      isa_ok $client->retr('foo.txt', \$data)->recv, 'AnyEvent::FTP::Response';
      is $data, "here is some data eh\nline 2\n", 'retr ok';
    };

    isa_ok $client->rename('foo.txt', 'bar.txt')->recv, 'AnyEvent::FTP::Response';

    do {
      my $res = $client->nlst->recv;
      is $res, array { etc() };
      is scalar(@$res), 1, 'list not empty';
      is $res->[0], 'bar.txt';
    };

    do {
      my $res = $client->list->recv;

t/anyevent_ftp_client.t  view on Meta::CPAN

    isa_ok $res, 'AnyEvent::FTP::Response';
    my $code = eval { $res->code };
    diag $@ if $@;
    like $code, qr{^[45]50$}, 'code = ' . $code;
  };

  $client->quit->recv;

};

subtest 'rename' => sub {
  reset_timeout;
  skip_all 'requires client and server on localhost' if $ENV{AEF_REMOTE};

  our $config;
  $config->{dir} = tempdir( CLEANUP => 1 );

  my $client = AnyEvent::FTP::Client->new;

  prep_client( $client );

t/anyevent_ftp_client.t  view on Meta::CPAN

  };

  do {
    my $from = File::Spec->catfile($config->{dir}, 'pepper.txt');
    do { open my $fh, '>', $from; close $fh; };
    my $to   = File::Spec->catfile($config->{dir}, 'coke.txt');

    ok  -e $from, "EX: $from";
    ok !-e $to,   "NO: $to";

    my $res = eval { $client->rename($from, $to)->recv };
    diag $@ if $@;
    isa_ok $res, 'AnyEvent::FTP::Response';

    ok !-e $from, "NO: $from";
    ok  -e $to,   "EX: $to";
  };

  $client->quit->recv;
};

t/anyevent_ftp_server_context_memory__rename.t  view on Meta::CPAN

  ->message_is('No such file or directory');

$t->command_ok(RNFR => "../")
  ->code_is(550)
  ->message_is('No such file or directory');

$t->command_ok(RNFR => "dir/foo.txt")
  ->code_is(350)
  ->message_is('File or directory exists, ready for destination name');

todo "shouldn't be able to rename to root" => sub {

$t->command_ok(RNTO => "/")
  ->code_is(550);

};

done_testing;



( run in 0.447 second using v1.01-cache-2.11-cpan-131fc08a04b )