Net::FTPServer::DirHandle - A Net::FTPServer directory handle.


Net-FTPServer documentation Contained in the Net-FTPServer distribution.

Index


Code Index:

NAME

Top

Net::FTPServer::DirHandle - A Net::FTPServer directory handle.

SYNOPSIS

Top

  use Net::FTPServer::DirHandle;

DESCRIPTION

Top

METHODS

Top

$dirh = new Net::FTPServer::DirHandle ($ftps);

Create a new directory handle. The directory handle corresponds to "/".

$dirh = $dirh->parent;

Return the parent directory of the directory $dirh. If the directory is already "/", this returns the same directory handle.

$rv = $dirh->is_root;

Return true if the current directory is the root directory.

$handle = $dirh->get ($filename);

Return the file or directory $handle corresponding to the file $filename in directory $dirh. If there is no file or subdirectory of that name, then this returns undef.

$ref = $dirh->list ([$wildcard]);

Return a list of the contents of directory $dirh. The list returned is a reference to an array of pairs:

  [ $filename, $handle ]

The list returned does not include "." or "..".

The list is sorted into alphabetical order automatically.

$ref = $dirh->_list_status ([$wildcard]);

Just a dumb wrapper function. Returns the same thing as list_status(), but also includes the special directories "." and ".." if no wildcard is specified.

$ref = $dirh->list_status ([$wildcard]);

Return a list of the contents of directory $dirh and status information. The list returned is a reference to an array of triplets:

  [ $filename, $handle, $statusref ]

where $statusref is the tuple returned from the status method (see Net::FTPServer::Handle).

The list returned does not include "." or "..".

The list is sorted into alphabetical order automatically.

$rv = $dirh->delete;

Delete the current directory. If the delete command was successful, then return 0, else if there was an error return -1.

It is normally only possible to delete a directory if it is empty.

$rv = $dirh->mkdir ($name);

Create a subdirectory called $name within the current directory $dirh.

$file = $dirh->open ($filename, "r"|"w"|"a");

Open or create a file called $filename in the current directory, opening it for either read, write or append. This function returns a IO::File handle object.

AUTHORS

Top

Richard Jones (rich@annexia.org).

COPYRIGHT

Top

SEE ALSO

Top

Net::FTPServer(3), perl(1)


Net-FTPServer documentation Contained in the Net-FTPServer distribution.
# -*- perl -*-

# Net::FTPServer A Perl FTP Server
# Copyright (C) 2000 Bibliotech Ltd., Unit 2-3, 50 Carnwath Road,
# London, SW6 3EG, United Kingdom.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# $Id: DirHandle.pm,v 1.1 2003/09/28 11:50:45 rwmj Exp $

package Net::FTPServer::DirHandle;

use strict;

use vars qw($VERSION);
( $VERSION ) = '$Revision: 1.1 $ ' =~ /\$Revision:\s+([^\s]+)/;

use Carp qw(confess);

use Net::FTPServer::Handle;

use vars qw(@ISA);

@ISA = qw(Net::FTPServer::Handle);

sub new
  {
    my $class = shift;
    my $ftps = shift;

    # Only internal calls will supply the $path argument. It must end
    # with a "/".
    my $path = shift || "/";

    my $self = Net::FTPServer::Handle->new ($ftps);
    $self->{_pathname} = $path;

    return bless $self, $class;
  }

sub parent
  {
    my $self = shift;

    # Already in "/" ?
    return $self if $self->is_root;

    my $new_pathname = $self->{_pathname};
    $new_pathname =~ s,[^/]*/$,,;

    return Net::FTPServer::DirHandle->new ($self->{ftps}, $new_pathname);
  }

sub is_root
  {
    my $self = shift;

    return $self->{_pathname} eq "/";
  }

sub get
  {
    confess "virtual function";
  }

sub list
  {
    confess "virtual function";
  }


sub _list_status
  {
    my $self = shift;
    my $wildcard = shift;
    my @array = ();
    unless ($wildcard)
      {
	# I suppose that there will be some FTP clients out there which
	# will get confused if they don't see . and .. entries.
	push (@array, [ ".",  $self ]);
	push (@array, [ "..", $self->parent ]);
      }
    push (@array, @{ $self->list_status ($wildcard) });
    return \@array;
  }

sub list_status
  {
    confess "virtual function";
  }

sub delete
  {
    confess "virtual function";
  }

sub mkdir
  {
    confess "virtual function";
  }

sub open
  {
    confess "virtual function";
  }

1 # So that the require or use succeeds.

__END__