AnyEvent-FTP

 view release on metacpan or  search on metacpan

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


=head2 mode

 $client->mode

Specify the transfer mode.  This is not used by modern FTP servers.  See RFC959 for details.

=head2 stat

 $client->stat;
 $client->stat($path);

Get information about a file or directory on the remote server.  The actual format is totally
server dependent.

=head2 user

 $client->user( $username );

Specify the user to login as.  See C<connect> or C<login> methods for a shortcut.

share/ppt/ls.pl  view on Meta::CPAN

	my $Options = shift;	# option arguments hashref
	local *DH;		# directory handle
	my %Attributes = ();	# entry/attributes hash
	my @Entries = ();	# entries in original order
	my $Name = "";		# entry name

	if (!opendir(DH, $_[0]) || exists($Options{'d'})) {
		if (-e $_[0]) {
			closedir(DH) if (defined(DH));
			push(@Entries, $_[0]);
			$Attributes{$_[0]} = stat($_[0]);
			push(@Entries, \%Attributes);
			return @Entries;
		}
		print "pls: can't access '$_[0]': $!\n";
		return ();
	}
	while ($Name = readdir(DH)) {
		next if (!exists($Options->{'a'}) &&
		 $Name =~ m/^\./o);
		push(@Entries, $Name);
		$Attributes{$Name} = stat( File::Spec->catfile( $_[0], $Name ) );
	}
	closedir(DH);

	# ------ return list with %Attributes ref at end
	push(@Entries, \%Attributes);
	return @Entries;
}

# ------ format directory entry
sub EntryFormat {

share/ppt/ls.pl  view on Meta::CPAN


# ------ process arguments
getopts('1ACFLRSTWacdfgiklmnopqrstux', \%Options);

# ------ get (or guess) window size
if (ioctl(STDOUT, $TIOCGWINSZ, $WinSize)) {
	($WinRows, $WinCols, $Xpixel, $Ypixel) = unpack('S4', $WinSize);
} else {
	$WinCols = 80;
}
$Attributes = stat(STDOUT);
if ($Attributes->mode & 0140000) {
	$Options{'1'} = '1';
}

# ------ current directory if no arguments
if ($#ARGV < 0) {
	List('.', \%Options, 0, DirEntries(\%Options, "."));

# ------ named files/directories if arguments
} else {

share/ppt/ls.pl  view on Meta::CPAN

	foreach $Arg (@ARGV) {
		if (!exists($Options{'d'}) && -d $Arg) {
			$ArgCount++;
			push(@Dirs, $Arg);
		} else {
			$ArgCount += 2;
			push(@Files, $Arg);
		}
	}
	foreach $Arg (@Files) {
		$Attributes{$Arg} = stat($Arg);
	}
	foreach $Arg (Order(\%Options, \%Attributes, @Files)) {
		$First = 0;
		List($Arg, \%Options, 0,
		 DirEntries(\%Options, $Arg));
	}
	foreach $Arg (@Dirs) {
		$Attributes{$Arg} = stat($Arg);
	}
	foreach $Arg (Order(\%Options, \%Attributes, @Dirs)) {
		if (!exists($Options{'R'})) {
			print "\n" if (!$First);
			$First = 0;
			print "$Arg:\n" if ($ArgCount > 0);
		}
		List($Arg, \%Options, 0,
		 DirEntries(\%Options, $Arg));
	}

share/ppt/ls.pl  view on Meta::CPAN

=item -u

Sort by descending last access time.

=back

=head1 ENVIRONMENT

=head1 BUGS

The file metadata from stat() is used, which may not necessarily
mean much on non-Unix systems.  Specifically, the uid, gid, inode,
and block numbers may be meaningless (or less than meaningful
at least).

The B<-l> option does not yet list the major and minor
device numbers for special files, but it does list
the value of the 'dev' field as 2 hex 16-bit words.
Doing this properly would
probably require filesystem type probing.

t/anyevent_ftp_client.t  view on Meta::CPAN

  do {
    my $res = eval { $client->stat->recv };
    diag $@ if $@;
    isa_ok $res, 'AnyEvent::FTP::Response';
    my $code = eval { $res->code };
    diag $@ if $@;
    like $code, qr{^21[123]$}, 'code = ' . $code;
  };

  do {
    my $res = eval { $client->stat('/')->recv };
    diag $@ if $@;
    isa_ok $res, 'AnyEvent::FTP::Response';
    my $code = eval { $res->code };
    diag $@ if $@;
    like $code, qr{^21[123]$}, 'code = ' . $code;
  };

  SKIP: {
    skip 'wu-ftpd does not return [45]50 on bogus file', 2 if $detect->{wu};
    skip 'pure-FTPd does not return [45]50 on bogus file', 2 if $detect->{pu};
    skip 'vsftp does not return [45]50 on bogus file', 2 if $detect->{vs};
    skip 'IIS does not return [45]50 on bogus file', 2 if $detect->{ms};
    skip 'bftp does not return [45]50 on bogus file', 2 if $detect->{xb};
    eval { $client->stat('bogus')->recv };
    my $res = $@;
    isa_ok $res, 'AnyEvent::FTP::Response';
    my $code = eval { $res->code };
    diag $@ if $@;
    like $code, qr{^[45]50$}, 'code = ' . $code;
  };

  $client->quit->recv;

};



( run in 0.507 second using v1.01-cache-2.11-cpan-49f99fa48dc )