);
exit;
}
sub error_here {
my($reason, @param) = @_;
start_html($q) unless $conf->{'header_sent'};
if ($reason eq "bad_login"){
print "$msg[45]";
clear_info();
start_form();
print qq( );
end_html();
exit;
}
if ($reason eq "bad_site"){
print "$msg[46]";
exit;
}
if ($reason eq "not_renamed"){
print "$msg[47] $param[0] => $param[1]. ";
}
if ($reason eq "chmod_not_supported"){
print "$msg[48] ";
}
if ($reason eq "not_chmodded"){
print "$msg[49] $param[0] => $param[1] ";
}
if ($reason eq "dir_not_deleted"){
print "$msg[50] $param[0]. ";
}
if ($reason eq "file_not_deleted"){
print "$msg[51] $param[0]. ";
}
if ($reason eq "not_deleted"){
print "$msg[124] $param[0]. ";
}
if ($reason eq "dir_not_created"){
print "$msg[54] $param[0]. ";
}
if ($reason eq 'bad_dir'){
print "$msg[55] $param[0]. ";
}
if ($reason eq 'bad_upload'){
print "$msg[56] $param[0]. ";
}
if ($reason eq "bad_name"){
print "$msg[57] $param[0]. $msg[58] ";
}
if ($reason eq "session_expired"){
if($page eq 'selector'){
print qq($msg[93] Login );
}
else {
print qq($msg[93] Login );
}
end_html();
}
if ($reason eq "session_retrieve"){
if($page eq 'selector'){
print qq($msg[94] Login );
}
else {
print qq($msg[94] Login );
}
end_html();
}
if ($reason eq 'no_session_id'){
print "No session id! ";
}
if ($reason eq "generic"){
print "$msg[59]: ", $param[0];
}
}
sub set_language {
@msg = ("", "Site", "Current Directory", "", "Logout", "New Dir", "New Text File",
"Upload Files", "Change Dir", " Up ", "Rename", "Chmod", "Edit File", "Delete File",
"Delete Dir", "Directories", "Files", "No directories", "No files", "Name", "Mode",
"Size", "Old name", "New name", "Cannot get file", "Edit", "Cannot open file",
"Cannot close file", "Cannot delete file", "Please select files to upload.",
"Please make sure you are not making a fatal mistake. Only checked files(directories) will be processed.",
"Host address", "User", "Password", "Start directory", "Login", "Clear", "has been renamed to",
"has been chmodded to", "Directory", "has been deleted", "File", "has been modifed",
"has been created", "has been uploaded", "Cannot login to host. Either the host is unreachable or you entered the wrong data.",
"Cannot connect to host. Host seems not to answer.", "Cannot rename",
"chmod command not supported on this FTP server.", "Cannot chmod.",
"Cannot delete directory", "Cannot delete file", "Cannot modify file",
"Cannot get file from FTP server", "Cannot create directory", "Cannot move to",
"Cannot upload file", "Illegal new name for", "Please use only alphanumerics, '.' and '+'.",
"FTP error occured", "", "Host Address", "", "", "Edit", "Delete", "", "", "", "", "", "",
"", "", "", "", "", "Confirm Rename", "Confirm Chmod", "Confirm Delete File",
"Confirm Delete Dir", "", "Confirm Upload", "Cancel", "", "", "Cannot open directory",
"Cannot close directory", "", "Download", "File has not been modifed",
"Cannot save temporary file on local server", "File has not been uploaded",
"Your session has expired, you have to login again.",
"Cannot retrieve session data. Try to login again.", "Uploading to", "Select All",
"Clear All", "Save and Exit", "Confirm Move", "Move", "", "Select Dir", "", "", "", "",
"", "", "File name", "", "", "Actions", "Owner", "Group", "Type", "Confirm Delete",
"Please enter the new directory name", "", "", "Date", "Please enter the file name!",
"Selected", "Please select files or directories.", "Cannot delete",);
}
# Don't forget to return a true value
1;
WFTP_FILE_END: www_ftp/wftp_common.pl
WFTP_FILE_START: www_ftp/wftp_conf.pl
###########################################################
# WWW FTP Client Pro configuration file
###########################################################
# GENERAL CONFIGURATION
#number of upload fields
$conf->{upload_files} = 1;
#session lifetime in seconds
$conf->{session_lifetime} = 1000;
#directory for data. By default, it is the current one, but I recommend to set it
#up somewhere outside of the web path, no ending slash
$conf->{data_dir} = 'www_ftp';
#directory for temp sessions files, it will be in data dir
$conf->{session_dir} = 'sessions';
# HEADER COMPOSITION AND ACTIONS PERMISSIONS
# The following options are available:
# 'new_dir','new_text_file','upload','rename','chmod','move','edit','download','delete'
# and 'sep' for a separator. This defines the position of the action buttons and at the
# same time permissions to perform these actions.
# Set up buttons for the first row
$conf->{'header'}->[1] = ['new_dir','sep','new_text_file','sep','upload'];
# and for the second one
$conf->{'header'}->[2] = ['rename','chmod','move','sep','edit','download','sep','delete'];
# finally the version of the product
$conf->{'ver'} = '3.0.2';
# Don't forget to return a true value
1;
WFTP_FILE_END: www_ftp/wftp_conf.pl
WFTP_FILE_START: www_ftp/Net/Cmd.pm
# Net::Cmd.pm
#
# Copyright (c) 1995-1997 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Net::Cmd;
require 5.001;
require Exporter;
use strict;
use vars qw(@ISA @EXPORT $VERSION);
use Carp;
$VERSION = "2.18";
@ISA = qw(Exporter);
@EXPORT = qw(CMD_INFO CMD_OK CMD_MORE CMD_REJECT CMD_ERROR CMD_PENDING);
sub CMD_INFO { 1 }
sub CMD_OK { 2 }
sub CMD_MORE { 3 }
sub CMD_REJECT { 4 }
sub CMD_ERROR { 5 }
sub CMD_PENDING { 0 }
my %debug = ();
sub _print_isa
{
no strict qw(refs);
my $pkg = shift;
my $cmd = $pkg;
$debug{$pkg} ||= 0;
my %done = ();
my @do = ($pkg);
my %spc = ( $pkg , "");
print STDERR "\n";
while ($pkg = shift @do)
{
next if defined $done{$pkg};
$done{$pkg} = 1;
my $v = defined ${"${pkg}::VERSION"}
? "(" . ${"${pkg}::VERSION"} . ")"
: "";
my $spc = $spc{$pkg};
print STDERR "$cmd: ${spc}${pkg}${v}\n";
if(@{"${pkg}::ISA"})
{
@spc{@{"${pkg}::ISA"}} = (" " . $spc{$pkg}) x @{"${pkg}::ISA"};
unshift(@do, @{"${pkg}::ISA"});
}
}
print STDERR "\n";
}
sub debug
{
@_ == 1 or @_ == 2 or croak 'usage: $obj->debug([LEVEL])';
my($cmd,$level) = @_;
my $pkg = ref($cmd) || $cmd;
my $oldval = 0;
if(ref($cmd))
{
$oldval = ${*$cmd}{'net_cmd_debug'} || 0;
}
else
{
$oldval = $debug{$pkg} || 0;
}
return $oldval
unless @_ == 2;
$level = $debug{$pkg} || 0
unless defined $level;
_print_isa($pkg)
if($level && !exists $debug{$pkg});
if(ref($cmd))
{
${*$cmd}{'net_cmd_debug'} = $level;
}
else
{
$debug{$pkg} = $level;
}
$oldval;
}
sub message
{
@_ == 1 or croak 'usage: $obj->message()';
my $cmd = shift;
wantarray ? @{${*$cmd}{'net_cmd_resp'}}
: join("", @{${*$cmd}{'net_cmd_resp'}});
}
sub debug_text { $_[2] }
sub debug_print
{
my($cmd,$out,$text) = @_;
print STDERR $cmd,($out ? '>>> ' : '<<< '), $cmd->debug_text($out,$text);
}
sub code
{
@_ == 1 or croak 'usage: $obj->code()';
my $cmd = shift;
${*$cmd}{'net_cmd_code'} = "000"
unless exists ${*$cmd}{'net_cmd_code'};
${*$cmd}{'net_cmd_code'};
}
sub status
{
@_ == 1 or croak 'usage: $obj->status()';
my $cmd = shift;
substr(${*$cmd}{'net_cmd_code'},0,1);
}
sub set_status
{
@_ == 3 or croak 'usage: $obj->set_status(CODE, MESSAGE)';
my $cmd = shift;
my($code,$resp) = @_;
$resp = [ $resp ]
unless ref($resp);
(${*$cmd}{'net_cmd_code'},${*$cmd}{'net_cmd_resp'}) = ($code, $resp);
1;
}
sub command
{
my $cmd = shift;
return $cmd unless defined fileno($cmd);
$cmd->dataend()
if(exists ${*$cmd}{'net_cmd_lastch'});
if (scalar(@_))
{
local $SIG{PIPE} = 'IGNORE';
my $str = join(" ", map { /\n/ ? do { my $n = $_; $n =~ tr/\n/ /; $n } : $_; } @_) . "\015\012";
my $len = length $str;
my $swlen;
$cmd->close
unless (defined($swlen = syswrite($cmd,$str,$len)) && $swlen == $len);
$cmd->debug_print(1,$str)
if($cmd->debug);
${*$cmd}{'net_cmd_resp'} = []; # the response
${*$cmd}{'net_cmd_code'} = "000"; # Made this one up :-)
}
$cmd;
}
sub ok
{
@_ == 1 or croak 'usage: $obj->ok()';
my $code = $_[0]->code;
0 < $code && $code < 400;
}
sub unsupported
{
my $cmd = shift;
${*$cmd}{'net_cmd_resp'} = [ 'Unsupported command' ];
${*$cmd}{'net_cmd_code'} = 580;
0;
}
sub getline
{
my $cmd = shift;
${*$cmd}{'net_cmd_lines'} ||= [];
return shift @{${*$cmd}{'net_cmd_lines'}}
if scalar(@{${*$cmd}{'net_cmd_lines'}});
my $partial = defined(${*$cmd}{'net_cmd_partial'})
? ${*$cmd}{'net_cmd_partial'} : "";
my $fd = fileno($cmd);
return undef
unless defined $fd;
my $rin = "";
vec($rin,$fd,1) = 1;
my $buf;
until(scalar(@{${*$cmd}{'net_cmd_lines'}}))
{
my $timeout = $cmd->timeout || undef;
my $rout;
if (select($rout=$rin, undef, undef, $timeout))
{
unless (sysread($cmd, $buf="", 1024))
{
carp(ref($cmd) . ": Unexpected EOF on command channel")
if $cmd->debug;
$cmd->close;
return undef;
}
substr($buf,0,0) = $partial; ## prepend from last sysread
my @buf = split(/\015?\012/, $buf, -1); ## break into lines
$partial = pop @buf;
push(@{${*$cmd}{'net_cmd_lines'}}, map { "$_\n" } @buf);
}
else
{
carp("$cmd: Timeout") if($cmd->debug);
return undef;
}
}
${*$cmd}{'net_cmd_partial'} = $partial;
shift @{${*$cmd}{'net_cmd_lines'}};
}
sub ungetline
{
my($cmd,$str) = @_;
${*$cmd}{'net_cmd_lines'} ||= [];
unshift(@{${*$cmd}{'net_cmd_lines'}}, $str);
}
sub parse_response
{
return ()
unless $_[1] =~ s/^(\d\d\d)(.?)//o;
($1, $2 eq "-");
}
sub response
{
my $cmd = shift;
my($code,$more) = (undef) x 2;
${*$cmd}{'net_cmd_resp'} ||= [];
while(1)
{
my $str = $cmd->getline();
return CMD_ERROR
unless defined($str);
$cmd->debug_print(0,$str)
if ($cmd->debug);
($code,$more) = $cmd->parse_response($str);
unless(defined $code)
{
$cmd->ungetline($str);
last;
}
${*$cmd}{'net_cmd_code'} = $code;
push(@{${*$cmd}{'net_cmd_resp'}},$str);
last unless($more);
}
substr($code,0,1);
}
sub read_until_dot
{
my $cmd = shift;
my $fh = shift;
my $arr = [];
while(1)
{
my $str = $cmd->getline() or return undef;
$cmd->debug_print(0,$str)
if ($cmd->debug & 4);
last if($str =~ /^\.\r?\n/o);
$str =~ s/^\.\././o;
if (defined $fh)
{
print $fh $str;
}
else
{
push(@$arr,$str);
}
}
$arr;
}
sub datasend
{
my $cmd = shift;
my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_;
my $line = join("" ,@$arr);
return 0 unless defined(fileno($cmd));
return 1
unless length($line);
if($cmd->debug)
{
my $b = "$cmd>>> ";
print STDERR $b,join("\n$b",split(/\n/,$line)),"\n";
}
$line =~ s/\n/\015\012/sgo;
${*$cmd}{'net_cmd_lastch'} ||= " ";
$line = ${*$cmd}{'net_cmd_lastch'} . $line;
$line =~ s/(\012\.)/$1./sog;
${*$cmd}{'net_cmd_lastch'} = substr($line,-1,1);
my $len = length($line) - 1;
my $offset = 1;
my $win = "";
vec($win,fileno($cmd),1) = 1;
my $timeout = $cmd->timeout || undef;
while($len)
{
my $wout;
if (select(undef,$wout=$win, undef, $timeout) > 0)
{
my $w = syswrite($cmd, $line, $len, $offset);
unless (defined($w))
{
carp("$cmd: $!") if $cmd->debug;
return undef;
}
$len -= $w;
$offset += $w;
}
else
{
carp("$cmd: Timeout") if($cmd->debug);
return undef;
}
}
1;
}
sub dataend
{
my $cmd = shift;
return 0 unless defined(fileno($cmd));
return 1
unless(exists ${*$cmd}{'net_cmd_lastch'});
if(${*$cmd}{'net_cmd_lastch'} eq "\015")
{
syswrite($cmd,"\012",1);
print STDERR "\n"
if($cmd->debug);
}
elsif(${*$cmd}{'net_cmd_lastch'} ne "\012")
{
syswrite($cmd,"\015\012",2);
print STDERR "\n"
if($cmd->debug);
}
print STDERR "$cmd>>> .\n"
if($cmd->debug);
syswrite($cmd,".\015\012",3);
delete ${*$cmd}{'net_cmd_lastch'};
$cmd->response() == CMD_OK;
}
1;
__END__
=head1 NAME
Net::Cmd - Network Command class (as used by FTP, SMTP etc)
=head1 SYNOPSIS
use Net::Cmd;
@ISA = qw(Net::Cmd);
=head1 DESCRIPTION
C is a collection of methods that can be inherited by a sub class
of C. These methods implement the functionality required for a
command based protocol, for example FTP and SMTP.
=head1 USER METHODS
These methods provide a user interface to the C object.
=over 4
=item debug ( VALUE )
Set the level of debug information for this object. If C is not given
then the current state is returned. Otherwise the state is changed to
C and the previous state returned.
Set the level of debug information for this object. If no argument is
given then the current state is returned. Otherwise the state is
changed to C<$value>and the previous state returned. Different packages
may implement different levels of debug but, a non-zero value result in
copies of all commands and responses also being sent to STDERR.
If C is C then the debug level will be set to the default
debug level for the class.
This method can also be called as a I method to set/get the default
debug level for a given class.
=item message ()
Returns the text message returned from the last command
=item code ()
Returns the 3-digit code from the last command. If a command is pending
then the value 0 is returned
=item ok ()
Returns non-zero if the last code value was greater than zero and
less than 400. This holds true for most command servers. Servers
where this does not hold may override this method.
=item status ()
Returns the most significant digit of the current status code. If a command
is pending then C is returned.
=item datasend ( DATA )
Send data to the remote server, converting LF to CRLF. Any line starting
with a '.' will be prefixed with another '.'.
C may be an array or a reference to an array.
=item dataend ()
End the sending of data to the remote server. This is done by ensuring that
the data already sent ends with CRLF then sending '.CRLF' to end the
transmission. Once this data has been sent C calls C and
returns true if C returns CMD_OK.
=back
=head1 CLASS METHODS
These methods are not intended to be called by the user, but used or
over-ridden by a sub-class of C
=over 4
=item debug_print ( DIR, TEXT )
Print debugging information. C denotes the direction I being
data being sent to the server. Calls C before printing to
STDERR.
=item debug_text ( TEXT )
This method is called to print debugging information. TEXT is
the text being sent. The method should return the text to be printed
This is primarily meant for the use of modules such as FTP where passwords
are sent, but we do not want to display them in the debugging information.
=item command ( CMD [, ARGS, ... ])
Send a command to the command server. All arguments a first joined with
a space character and CRLF is appended, this string is then sent to the
command server.
Returns undef upon failure
=item unsupported ()
Sets the status code to 580 and the response text to 'Unsupported command'.
Returns zero.
=item response ()
Obtain a response from the server. Upon success the most significant digit
of the status code is returned. Upon failure, timeout etc., I is
returned.
=item parse_response ( TEXT )
This method is called by C as a method with one argument. It should
return an array of 2 values, the 3-digit status code and a flag which is true
when this is part of a multi-line response and this line is not the list.
=item getline ()
Retrieve one line, delimited by CRLF, from the remote server. Returns I
upon failure.
B: If you do use this method for any reason, please remember to add
some C calls into your method.
=item ungetline ( TEXT )
Unget a line of text from the server.
=item read_until_dot ()
Read data from the remote server until a line consisting of a single '.'.
Any lines starting with '..' will have one of the '.'s removed.
Returns a reference to a list containing the lines, or I upon failure.
=back
=head1 EXPORTS
C exports six subroutines, five of these, C, C,
C, C and C ,correspond to possible results
of C and C. The sixth is C.
=head1 AUTHOR
Graham Barr
=head1 COPYRIGHT
Copyright (c) 1995-1997 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
WFTP_FILE_END: www_ftp/Net/Cmd.pm
WFTP_FILE_START: www_ftp/Net/Config.pm
package Net::Config;
# $Id: //depot/libnet/Net/Config.pm#6 $
require Exporter;
use vars qw(@ISA @EXPORT %NetConfig $VERSION $CONFIGURE $LIBNET_CFG);
use Socket qw(inet_aton inet_ntoa);
use strict;
@EXPORT = qw(%NetConfig);
@ISA = qw(Net::LocalCfg Exporter);
$VERSION = "1.04";
eval { local $SIG{__DIE__}; require Net::LocalCfg };
%NetConfig = (
nntp_hosts => [],
snpp_hosts => [],
pop3_hosts => [],
smtp_hosts => [],
ph_hosts => [],
daytime_hosts => [],
time_hosts => [],
inet_domain => undef,
ftp_firewall => undef,
ftp_ext_passive => 0,
ftp_int_passive => 0,
test_hosts => 1,
test_exist => 1,
);
my $file = __FILE__;
my $ref;
$file =~ s/Config.pm/libnet.cfg/;
if ( -f $file ) {
$ref = eval { do $file };
if (ref($ref) eq 'HASH') {
%NetConfig = (%NetConfig, %{ $ref });
$LIBNET_CFG = $file;
}
}
if ($< == $> and !$CONFIGURE) {
my $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
$file = $home . "/.libnetrc";
$ref = eval { do $file } if -f $file;
%NetConfig = (%NetConfig, %{ $ref })
if ref($ref) eq 'HASH';
}
my ($k,$v);
while(($k,$v) = each %NetConfig) {
$v = [ $v ]
if($k =~ /_hosts$/ && !ref($v));
}
# Take a hostname and determine if it is inside te firewall
sub requires_firewall {
shift; # ignore package
my $host = shift;
return 0 unless defined $NetConfig{'ftp_firewall'};
$host = inet_aton($host) or return -1;
$host = inet_ntoa($host);
if(exists $NetConfig{'local_netmask'}) {
my $quad = unpack("N",pack("C*",split(/\./,$host)));
my $list = $NetConfig{'local_netmask'};
$list = [$list] unless ref($list);
foreach (@$list) {
my($net,$bits) = (m#^(\d+\.\d+\.\d+\.\d+)/(\d+)$#) or next;
my $mask = ~0 << (32 - $bits);
my $addr = unpack("N",pack("C*",split(/\./,$net)));
return 0 if (($addr & $mask) == ($quad & $mask));
}
return 1;
}
return 0;
}
use vars qw(*is_external);
*is_external = \&requires_firewall;
1;
__END__
=head1 NAME
Net::Config - Local configuration data for libnet
=head1 SYNOPSYS
use Net::Config qw(%NetConfig);
=head1 DESCRIPTION
C holds configuration data for the modules in the libnet
distribuion. During installation you will be asked for these values.
The configuration data is held globally in a file in the perl installation
tree, but a user may override any of these values by providing thier own. This
can be done by having a C<.libnetrc> file in thier home directory. This file
should return a reference to a HASH containing the keys described below.
For example
# .libnetrc
{
nntp_hosts => [ "my_prefered_host" ],
ph_hosts => [ "my_ph_server" ],
}
__END__
=head1 METHODS
C defines the following methods. They are methods as they are
invoked as class methods. This is because C inherits from
C so you can override these methods if you want.
=over 4
=item requires_firewall HOST
Attempts to determine if a given host is outside your firewall. Possible
return values are.
-1 Cannot lookup hostname
0 Host is inside firewall (or there is no ftp_firewall entry)
1 Host is outside the firewall
This is done by using hostname lookup and the C entry in
the configuration data.
=back
=head1 NetConfig VALUES
=over 4
=item nntp_hosts
=item snpp_hosts
=item pop3_hosts
=item smtp_hosts
=item ph_hosts
=item daytime_hosts
=item time_hosts
Each is a reference to an array of hostnames (in order of preference),
which should be used for the given protocol
=item inet_domain
Your internet domain name
=item ftp_firewall
If you have an FTP proxy firewall (B a HTTP or SOCKS firewall)
then this value should be set to the firewall hostname. If your firewall
does not listen to port 21, then this value should be set to
C<"hostname:port"> (eg C<"hostname:99">)
=item ftp_ext_passive
=item ftp_int_pasive
FTP servers normally work on a non-passive mode. That is when you want to
transfer data you have to tell the server the address and port to
connect to.
With some firewalls this does not work as te server cannot
connect to your machine (because you are beind a firewall) and the firewall
does not re-write te command. In this case you should set C
to a I value.
Some servers are configured to only work in passive mode. If you have
one of these you can force C to always transfer in passive
mode, when not going via a firewall, by cetting C to
a I value.
=item local_netmask
A reference to a list of netmask strings in the form C<"134.99.4.0/24">.
These are used by the C function to determine if a given
host is inside or outside your firewall.
=back
The following entries are used during installation & testing on the
libnet package
=over 4
=item test_hosts
If true them C may attempt to connect to hosts given in the
configuration.
=item test_exists
If true the C will check each hostname given that it exists
=back
=cut
WFTP_FILE_END: www_ftp/Net/Config.pm
WFTP_FILE_START: www_ftp/Net/Domain.pm
# Net::Domain.pm
#
# Copyright (c) 1995-1998 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Net::Domain;
require Exporter;
use Carp;
use strict;
use vars qw($VERSION @ISA @EXPORT_OK);
use Net::Config;
@ISA = qw(Exporter);
@EXPORT_OK = qw(hostname hostdomain hostfqdn domainname);
$VERSION = "2.13"; # $Id: //depot/libnet/Net/Domain.pm#10 $
my($host,$domain,$fqdn) = (undef,undef,undef);
# Try every conceivable way to get hostname.
sub _hostname {
# we already know it
return $host
if(defined $host);
if ($^O eq 'MSWin32') {
require Socket;
my ($name,$alias,$type,$len,@addr) = gethostbyname($ENV{'COMPUTERNAME'}||'localhost');
while (@addr)
{
my $a = shift(@addr);
$host = gethostbyaddr($a,Socket::AF_INET());
last if defined $host;
}
if (index($host,'.') > 0) {
$fqdn = $host;
($host,$domain) = $fqdn =~ /^([^\.]+)\.(.*)$/;
}
return $host;
}
elsif ($^O eq 'MacOS') {
chomp ($host = `hostname`);
}
elsif ($^O eq 'VMS') { ## multiple varieties of net s/w makes this hard
$host = $ENV{'UCX$INET_HOST'} if defined($ENV{'UCX$INET_HOST'});
$host = $ENV{'MULTINET_HOST_NAME'} if defined($ENV{'MULTINET_HOST_NAME'});
if (index($host,'.') > 0) {
$fqdn = $host;
($host,$domain) = $fqdn =~ /^([^\.]+)\.(.*)$/;
}
return $host;
}
else {
local $SIG{'__DIE__'};
# syscall is preferred since it avoids tainting problems
eval {
my $tmp = "\0" x 256; ## preload scalar
eval {
package main;
require "syscall.ph";
defined(&main::SYS_gethostname);
}
|| eval {
package main;
require "sys/syscall.ph";
defined(&main::SYS_gethostname);
}
and $host = (syscall(&main::SYS_gethostname, $tmp, 256) == 0)
? $tmp
: undef;
}
# POSIX
|| eval {
require POSIX;
$host = (POSIX::uname())[1];
}
# trusty old hostname command
|| eval {
chop($host = `(hostname) 2>/dev/null`); # BSD'ish
}
# sysV/POSIX uname command (may truncate)
|| eval {
chop($host = `uname -n 2>/dev/null`); ## SYSV'ish && POSIX'ish
}
# Apollo pre-SR10
|| eval {
$host = (split(/[:\. ]/,`/com/host`,6))[0];
}
|| eval {
$host = "";
};
}
# remove garbage
$host =~ s/[\0\r\n]+//go;
$host =~ s/(\A\.+|\.+\Z)//go;
$host =~ s/\.\.+/\./go;
$host;
}
sub _hostdomain {
# we already know it
return $domain
if(defined $domain);
local $SIG{'__DIE__'};
return $domain = $NetConfig{'inet_domain'}
if defined $NetConfig{'inet_domain'};
# try looking in /etc/resolv.conf
# putting this here and assuming that it is correct, eliminates
# calls to gethostbyname, and therefore DNS lookups. This helps
# those on dialup systems.
local *RES;
if(open(RES,"/etc/resolv.conf")) {
while() {
$domain = $1
if(/\A\s*(?:domain|search)\s+(\S+)/);
}
close(RES);
return $domain
if(defined $domain);
}
# just try hostname and system calls
my $host = _hostname();
my(@hosts);
local($_);
@hosts = ($host,"localhost");
unless($host =~ /\./) {
my $dom = undef;
eval {
my $tmp = "\0" x 256; ## preload scalar
eval {
package main;
require "syscall.ph";
}
|| eval {
package main;
require "sys/syscall.ph";
}
and $dom = (syscall(&main::SYS_getdomainname, $tmp, 256) == 0)
? $tmp
: undef;
};
chop($dom = `domainname 2>/dev/null`)
unless(defined $dom);
if(defined $dom) {
my @h = ();
while(length($dom)) {
push(@h, "$host.$dom");
$dom =~ s/^[^.]+.//;
}
unshift(@hosts,@h);
}
}
# Attempt to locate FQDN
foreach (@hosts) {
my @info = gethostbyname($_);
next unless @info;
# look at real name & aliases
my $site;
foreach $site ($info[0], split(/ /,$info[1])) {
if(rindex($site,".") > 0) {
# Extract domain from FQDN
($domain = $site) =~ s/\A[^\.]+\.//;
return $domain;
}
}
}
# Look for environment variable
$domain ||= $ENV{LOCALDOMAIN} ||= $ENV{DOMAIN} || undef;
if(defined $domain) {
$domain =~ s/[\r\n\0]+//g;
$domain =~ s/(\A\.+|\.+\Z)//g;
$domain =~ s/\.\.+/\./g;
}
$domain;
}
sub domainname {
return $fqdn
if(defined $fqdn);
_hostname();
_hostdomain();
# Assumption: If the host name does not contain a period
# and the domain name does, then assume that they are correct
# this helps to eliminate calls to gethostbyname, and therefore
# eleminate DNS lookups
return $fqdn = $host . "." . $domain
if($host !~ /\./ && $domain =~ /\./);
# For hosts that have no name, just an IP address
return $fqdn = $host if $host =~ /^\d+(\.\d+){3}$/;
my @host = split(/\./, $host);
my @domain = split(/\./, $domain);
my @fqdn = ();
# Determine from @host & @domain the FQDN
my @d = @domain;
LOOP:
while(1) {
my @h = @host;
while(@h) {
my $tmp = join(".",@h,@d);
if((gethostbyname($tmp))[0]) {
@fqdn = (@h,@d);
$fqdn = $tmp;
last LOOP;
}
pop @h;
}
last unless shift @d;
}
if(@fqdn) {
$host = shift @fqdn;
until((gethostbyname($host))[0]) {
$host .= "." . shift @fqdn;
}
$domain = join(".", @fqdn);
}
else {
undef $host;
undef $domain;
undef $fqdn;
}
$fqdn;
}
sub hostfqdn { domainname() }
sub hostname {
domainname()
unless(defined $host);
return $host;
}
sub hostdomain {
domainname()
unless(defined $domain);
return $domain;
}
1; # Keep require happy
__END__
=head1 NAME
Net::Domain - Attempt to evaluate the current host's internet name and domain
=head1 SYNOPSIS
use Net::Domain qw(hostname hostfqdn hostdomain);
=head1 DESCRIPTION
Using various methods B to find the Fully Qualified Domain Name (FQDN)
of the current host. From this determine the host-name and the host-domain.
Each of the functions will return I if the FQDN cannot be determined.
=over 4
=item hostfqdn ()
Identify and return the FQDN of the current host.
=item hostname ()
Returns the smallest part of the FQDN which can be used to identify the host.
=item hostdomain ()
Returns the remainder of the FQDN after the I has been removed.
=back
=head1 AUTHOR
Graham Barr .
Adapted from Sys::Hostname by David Sundstrom
=head1 COPYRIGHT
Copyright (c) 1995-1998 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
WFTP_FILE_END: www_ftp/Net/Domain.pm
WFTP_FILE_START: www_ftp/Net/DummyInetd.pm
# Net::DummyInetd.pm
#
# Copyright (c) 1995-1997 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Net::DummyInetd;
require 5.002;
use IO::Handle;
use IO::Socket;
use strict;
use vars qw($VERSION);
use Carp;
$VERSION = do { my @r=(q$Revision: 1.6 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
sub _process
{
my $listen = shift;
my @cmd = @_;
my $vec = '';
my $r;
vec($vec,fileno($listen),1) = 1;
while(select($r=$vec,undef,undef,undef))
{
my $sock = $listen->accept;
my $pid;
if($pid = fork())
{
sleep 1;
close($sock);
}
elsif(defined $pid)
{
my $x = IO::Handle->new_from_fd($sock,"r");
open(STDIN,"<&=".fileno($x)) || die "$! $@";
close($x);
my $y = IO::Handle->new_from_fd($sock,"w");
open(STDOUT,">&=".fileno($y)) || die "$! $@";
close($y);
close($sock);
exec(@cmd) || carp "$! $@";
}
else
{
close($sock);
carp $!;
}
}
exit -1;
}
sub new
{
my $self = shift;
my $type = ref($self) || $self;
my $listen = IO::Socket::INET->new(Listen => 5, Proto => 'tcp');
my $pid;
return bless [ $listen->sockport, $pid ]
if($pid = fork());
_process($listen,@_);
}
sub port
{
my $self = shift;
$self->[0];
}
sub DESTROY
{
my $self = shift;
kill 9, $self->[1];
}
1;
__END__
=head1 NAME
Net::DummyInetd - A dummy Inetd server
=head1 SYNOPSIS
use Net::DummyInetd;
use Net::SMTP;
$inetd = new Net::DummyInetd qw(/usr/lib/sendmail -ba -bs);
$smtp = Net::SMTP->new('localhost', Port => $inetd->port);
=head1 DESCRIPTION
C is just what it's name says, it is a dummy inetd server.
Creation of a C will cause a child process to be spawned off
which will listen to a socket. When a connection arrives on this socket
the specified command is fork'd and exec'd with STDIN and STDOUT file
descriptors duplicated to the new socket.
This package was added as an example of how to use C to connect
to a C process, which is not the default, via SIDIN and STDOUT.
A C package will be available in the next release of C
=head1 CONSTRUCTOR
=over 4
=item new ( CMD )
Creates a new object and spawns a child process which listens to a socket.
C is a list, which will be passed to C when a new process needs
to be created.
=back
=head1 METHODS
=over 4
=item port
Returns the port number on which the I object is listening
=back
=head1 AUTHOR
Graham Barr
=head1 COPYRIGHT
Copyright (c) 1995-1997 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
WFTP_FILE_END: www_ftp/Net/DummyInetd.pm
WFTP_FILE_START: www_ftp/Net/FTP.pm
# Net::FTP.pm
#
# Copyright (c) 1995-8 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Documentation (at end) improved 1996 by Nathan Torkington .
package Net::FTP;
require 5.001;
use strict;
use vars qw(@ISA $VERSION);
use Carp;
use Socket 1.3;
use IO::Socket;
use Time::Local;
use Net::Cmd;
use Net::Config;
# use AutoLoader qw(AUTOLOAD);
$VERSION = "2.56"; # $Id:$
@ISA = qw(Exporter Net::Cmd IO::Socket::INET);
# Someday I will "use constant", when I am not bothered to much about
# compatability with older releases of perl
use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);
# Name is too long for AutoLoad, it clashes with pasv_xfer
sub pasv_xfer_unique {
my($sftp,$sfile,$dftp,$dfile) = @_;
$sftp->pasv_xfer($sfile,$dftp,$dfile,1);
}
1;
# Having problems with AutoLoader
#__END__
sub new
{
my $pkg = shift;
my $peer = shift;
my %arg = @_;
my $host = $peer;
my $fire = undef;
if(exists($arg{Firewall}) || Net::Config->requires_firewall($peer))
{
$fire = $arg{Firewall}
|| $ENV{FTP_FIREWALL}
|| $NetConfig{ftp_firewall}
|| undef;
if(defined $fire)
{
$peer = $fire;
delete $arg{Port};
}
}
my $ftp = $pkg->SUPER::new(PeerAddr => $peer,
PeerPort => $arg{Port} || 'ftp(21)',
Proto => 'tcp',
Timeout => defined $arg{Timeout}
? $arg{Timeout}
: 120
) or return undef;
${*$ftp}{'net_ftp_host'} = $host; # Remote hostname
${*$ftp}{'net_ftp_type'} = 'A'; # ASCII/binary/etc mode
${*$ftp}{'net_ftp_blksize'} = abs($arg{'BlockSize'} || 10240);
${*$ftp}{'net_ftp_firewall'} = $fire
if(defined $fire);
${*$ftp}{'net_ftp_passive'} = int
exists $arg{Passive}
? $arg{Passive}
: exists $ENV{FTP_PASSIVE}
? $ENV{FTP_PASSIVE}
: defined $fire
? $NetConfig{ftp_ext_passive}
: $NetConfig{ftp_int_passive}; # Whew! :-)
$ftp->hash(exists $arg{Hash} ? $arg{Hash} : 0, 1024);
$ftp->autoflush(1);
$ftp->debug(exists $arg{Debug} ? $arg{Debug} : undef);
unless ($ftp->response() == CMD_OK)
{
$ftp->close();
$@ = $ftp->message;
undef $ftp;
}
$ftp;
}
##
## User interface methods
##
sub hash {
my $ftp = shift; # self
my $prev = ${*$ftp}{'net_ftp_hash'} || [\*STDERR, 0];
unless(@_) {
return $prev;
}
my($h,$b) = @_;
if(@_ == 1) {
unless($h) {
delete ${*$ftp}{'net_ftp_hash'};
return $prev;
}
elsif(ref($h)) {
$b = 1024;
}
else {
($h,$b) = (\*STDERR,$h);
}
}
select((select($h), $|=1)[0]);
$b = 512 if $b < 512;
${*$ftp}{'net_ftp_hash'} = [$h, $b];
$prev;
}
sub quit
{
my $ftp = shift;
$ftp->_QUIT;
$ftp->close;
}
sub DESTROY
{
my $ftp = shift;
defined(fileno($ftp)) && $ftp->quit
}
sub ascii { shift->type('A',@_); }
sub binary { shift->type('I',@_); }
sub ebcdic
{
carp "TYPE E is unsupported, shall default to I";
shift->type('E',@_);
}
sub byte
{
carp "TYPE L is unsupported, shall default to I";
shift->type('L',@_);
}
# Allow the user to send a command directly, BE CAREFUL !!
sub quot
{
my $ftp = shift;
my $cmd = shift;
$ftp->command( uc $cmd, @_);
$ftp->response();
}
sub site
{
my $ftp = shift;
$ftp->command("SITE", @_);
$ftp->response();
}
sub mdtm
{
my $ftp = shift;
my $file = shift;
# Server Y2K bug workaround
#
# sigh; some idiotic FTP servers use ("19%d",tm.tm_year) instead of
# ("%d",tm.tm_year+1900). This results in an extra digit in the
# string returned. To account for this we allow an optional extra
# digit in the year. Then if the first two digits are 19 we use the
# remainder, otherwise we subtract 1900 from the whole year.
$ftp->_MDTM($file) && $ftp->message =~ /((\d\d)(\d\d\d?))(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
? timegm($8,$7,$6,$5,$4-1,$2 eq '19' ? $3 : ($1-1900))
: undef;
}
sub size {
my $ftp = shift;
my $file = shift;
my $io;
if($ftp->supported("SIZE")) {
return $ftp->_SIZE($file)
? ($ftp->message =~ /(\d+)/)[0]
: undef;
}
elsif($ftp->supported("STAT")) {
my @msg;
return undef
unless $ftp->_STAT($file) && (@msg = $ftp->message) == 3;
my $line;
foreach $line (@msg) {
return (split(/\s+/,$line))[4]
if $line =~ /^[-rw]{10}/
}
}
else {
my @files = $ftp->dir($file);
if(@files) {
return (split(/\s+/,$1))[4]
if $files[0] =~ /^([-rw]{10}.*)$/;
}
}
undef;
}
sub login {
my($ftp,$user,$pass,$acct) = @_;
my($ok,$ruser,$fwtype);
unless (defined $user) {
require Net::Netrc;
my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
($user,$pass,$acct) = $rc->lpa()
if ($rc);
}
$user ||= "anonymous";
$ruser = $user;
$fwtype = $NetConfig{'ftp_firewall_type'} || 0;
if ($fwtype && defined ${*$ftp}{'net_ftp_firewall'}) {
if ($fwtype == 1 || $fwtype == 7) {
$user .= '@' . ${*$ftp}{'net_ftp_host'};
}
else {
require Net::Netrc;
my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
my($fwuser,$fwpass,$fwacct) = $rc ? $rc->lpa() : ();
if ($fwtype == 5) {
$user = join('@',$user,$fwuser,${*$ftp}{'net_ftp_host'});
$pass = $pass . '@' . $fwpass;
}
else {
if ($fwtype == 2) {
$user .= '@' . ${*$ftp}{'net_ftp_host'};
}
elsif ($fwtype == 6) {
$fwuser .= '@' . ${*$ftp}{'net_ftp_host'};
}
$ok = $ftp->_USER($fwuser);
return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
$ok = $ftp->_PASS($fwpass || "");
return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
$ok = $ftp->_ACCT($fwacct)
if defined($fwacct);
if ($fwtype == 3) {
$ok = $ftp->command("SITE",${*$ftp}{'net_ftp_host'})->response;
}
elsif ($fwtype == 4) {
$ok = $ftp->command("OPEN",${*$ftp}{'net_ftp_host'})->response;
}
return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
}
}
}
$ok = $ftp->_USER($user);
# Some dumb firewalls don't prefix the connection messages
$ok = $ftp->response()
if ($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
if ($ok == CMD_MORE) {
unless(defined $pass) {
require Net::Netrc;
my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
($ruser,$pass,$acct) = $rc->lpa()
if ($rc);
$pass = "-" . (eval { (getpwuid($>))[0] } || $ENV{NAME} ) . '@'
if (!defined $pass && (!defined($ruser) || $ruser =~ /^anonymous/o));
}
$ok = $ftp->_PASS($pass || "");
}
$ok = $ftp->_ACCT($acct)
if (defined($acct) && ($ok == CMD_MORE || $ok == CMD_OK));
if ($fwtype == 7 && $ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'}) {
my($f,$auth,$resp) = _auth_id($ftp);
$ftp->authorize($auth,$resp) if defined($resp);
}
$ok == CMD_OK;
}
sub account
{
@_ == 2 or croak 'usage: $ftp->account( ACCT )';
my $ftp = shift;
my $acct = shift;
$ftp->_ACCT($acct) == CMD_OK;
}
sub _auth_id {
my($ftp,$auth,$resp) = @_;
unless(defined $resp)
{
require Net::Netrc;
$auth ||= eval { (getpwuid($>))[0] } || $ENV{NAME};
my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
|| Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
($auth,$resp) = $rc->lpa()
if ($rc);
}
($ftp,$auth,$resp);
}
sub authorize
{
@_ >= 1 || @_ <= 3 or croak 'usage: $ftp->authorize( [AUTH [, RESP]])';
my($ftp,$auth,$resp) = &_auth_id;
my $ok = $ftp->_AUTH($auth || "");
$ok = $ftp->_RESP($resp || "")
if ($ok == CMD_MORE);
$ok == CMD_OK;
}
sub rename
{
@_ == 3 or croak 'usage: $ftp->rename(FROM, TO)';
my($ftp,$from,$to) = @_;
$ftp->_RNFR($from)
&& $ftp->_RNTO($to);
}
sub type
{
my $ftp = shift;
my $type = shift;
my $oldval = ${*$ftp}{'net_ftp_type'};
return $oldval
unless (defined $type);
return undef
unless ($ftp->_TYPE($type,@_));
${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);
$oldval;
}
sub abort
{
my $ftp = shift;
send($ftp,pack("CCC", $TELNET_IAC, $TELNET_IP, $TELNET_IAC),MSG_OOB);
$ftp->command(pack("C",$TELNET_DM) . "ABOR");
${*$ftp}{'net_ftp_dataconn'}->close()
if defined ${*$ftp}{'net_ftp_dataconn'};
$ftp->response();
$ftp->status == CMD_OK;
}
sub get
{
my($ftp,$remote,$local,$where) = @_;
my($loc,$len,$buf,$resp,$localfd,$data);
local *FD;
$localfd = ref($local) || ref(\$local) eq "GLOB"
? fileno($local)
: undef;
($local = $remote) =~ s#^.*/##
unless(defined $local);
croak("Bad remote filename '$remote'\n")
if $remote =~ /[\r\n]/s;
${*$ftp}{'net_ftp_rest'} = $where
if ($where);
delete ${*$ftp}{'net_ftp_port'};
delete ${*$ftp}{'net_ftp_pasv'};
$data = $ftp->retr($remote) or
return undef;
if(defined $localfd)
{
$loc = $local;
}
else
{
$loc = \*FD;
unless(($where) ? open($loc,">>$local") : open($loc,">$local"))
{
carp "Cannot open Local file $local: $!\n";
$data->abort;
return undef;
}
}
if($ftp->type eq 'I' && !binmode($loc))
{
carp "Cannot binmode Local file $local: $!\n";
$data->abort;
close($loc) unless $localfd;
return undef;
}
$buf = '';
my($count,$hashh,$hashb,$ref) = (0);
($hashh,$hashb) = @$ref
if($ref = ${*$ftp}{'net_ftp_hash'});
my $blksize = ${*$ftp}{'net_ftp_blksize'};
while(1)
{
last unless $len = $data->read($buf,$blksize);
if($hashh) {
$count += $len;
print $hashh "#" x (int($count / $hashb));
$count %= $hashb;
}
my $written = syswrite($loc,$buf,$len);
unless(defined($written) && $written == $len)
{
carp "Cannot write to Local file $local: $!\n";
$data->abort;
close($loc)
unless defined $localfd;
return undef;
}
}
print $hashh "\n" if $hashh;
close($loc)
unless defined $localfd;
$data->close(); # implied $ftp->response
return $local;
}
sub cwd
{
@_ == 1 || @_ == 2 or croak 'usage: $ftp->cwd( [ DIR ] )';
my($ftp,$dir) = @_;
$dir = "/" unless defined($dir) && $dir =~ /\S/;
$dir eq ".."
? $ftp->_CDUP()
: $ftp->_CWD($dir);
}
sub cdup
{
@_ == 1 or croak 'usage: $ftp->cdup()';
$_[0]->_CDUP;
}
sub pwd
{
@_ == 1 || croak 'usage: $ftp->pwd()';
my $ftp = shift;
$ftp->_PWD();
$ftp->_extract_path;
}
# rmdir( $ftp, $dir, [ $recurse ] )
#
# Removes $dir on remote host via FTP.
# $ftp is handle for remote host
#
# If $recurse is TRUE, the directory and deleted recursively.
# This means all of its contents and subdirectories.
#
# Initial version contributed by Dinkum Software
#
sub rmdir
{
@_ == 2 || @_ == 3 or croak('usage: $ftp->rmdir( DIR [, RECURSE ] )');
# Pick off the args
my ($ftp, $dir, $recurse) = @_ ;
my $ok;
return $ok
if $ftp->_RMD( $dir ) || !$recurse;
# Try to delete the contents
# Get a list of all the files in the directory
my $filelist = $ftp->ls($dir);
return undef
unless $filelist && @$filelist; # failed, it is probably not a directory
# Go thru and delete each file or the directory
my $file;
foreach $file (map { m,/, ? $_ : "$dir/$_" } @$filelist)
{
next # successfully deleted the file
if $ftp->delete($file);
# Failed to delete it, assume its a directory
# Recurse and ignore errors, the final rmdir() will
# fail on any errors here
return $ok
unless $ok = $ftp->rmdir($file, 1) ;
}
# Directory should be empty
# Try to remove the directory again
# Pass results directly to caller
# If any of the prior deletes failed, this
# rmdir() will fail because directory is not empty
return $ftp->_RMD($dir) ;
}
sub mkdir
{
@_ == 2 || @_ == 3 or croak 'usage: $ftp->mkdir( DIR [, RECURSE ] )';
my($ftp,$dir,$recurse) = @_;
$ftp->_MKD($dir) || $recurse or
return undef;
my $path = $dir;
unless($ftp->ok)
{
my @path = split(m#(?=/+)#, $dir);
$path = "";
while(@path)
{
$path .= shift @path;
$ftp->_MKD($path);
$path = $ftp->_extract_path($path);
}
# If the creation of the last element was not sucessful, see if we
# can cd to it, if so then return path
unless($ftp->ok)
{
my($status,$message) = ($ftp->status,$ftp->message);
my $pwd = $ftp->pwd;
if($pwd && $ftp->cwd($dir))
{
$path = $dir;
$ftp->cwd($pwd);
}
else
{
undef $path;
}
$ftp->set_status($status,$message);
}
}
$path;
}
sub delete
{
@_ == 2 || croak 'usage: $ftp->delete( FILENAME )';
$_[0]->_DELE($_[1]);
}
sub put { shift->_store_cmd("stor",@_) }
sub put_unique { shift->_store_cmd("stou",@_) }
sub append { shift->_store_cmd("appe",@_) }
sub nlst { shift->_data_cmd("NLST",@_) }
sub list { shift->_data_cmd("LIST",@_) }
sub retr { shift->_data_cmd("RETR",@_) }
sub stor { shift->_data_cmd("STOR",@_) }
sub stou { shift->_data_cmd("STOU",@_) }
sub appe { shift->_data_cmd("APPE",@_) }
sub _store_cmd
{
my($ftp,$cmd,$local,$remote) = @_;
my($loc,$sock,$len,$buf,$localfd);
local *FD;
$localfd = ref($local) || ref(\$local) eq "GLOB"
? fileno($local)
: undef;
unless(defined $remote)
{
croak 'Must specify remote filename with stream input'
if defined $localfd;
require File::Basename;
$remote = File::Basename::basename($local);
}
croak("Bad remote filename '$remote'\n")
if $remote =~ /[\r\n]/s;
if(defined $localfd)
{
$loc = $local;
}
else
{
$loc = \*FD;
unless(open($loc,"<$local"))
{
carp "Cannot open Local file $local: $!\n";
return undef;
}
}
if($ftp->type eq 'I' && !binmode($loc))
{
carp "Cannot binmode Local file $local: $!\n";
return undef;
}
delete ${*$ftp}{'net_ftp_port'};
delete ${*$ftp}{'net_ftp_pasv'};
$sock = $ftp->_data_cmd($cmd, $remote) or
return undef;
my $blksize = ${*$ftp}{'net_ftp_blksize'};
my($count,$hashh,$hashb,$ref) = (0);
($hashh,$hashb) = @$ref
if($ref = ${*$ftp}{'net_ftp_hash'});
while(1)
{
last unless $len = sysread($loc,$buf="",$blksize);
if($hashh) {
$count += $len;
print $hashh "#" x (int($count / $hashb));
$count %= $hashb;
}
my $wlen;
unless(defined($wlen = $sock->write($buf,$len)) && $wlen == $len)
{
$sock->abort;
close($loc)
unless defined $localfd;
print $hashh "\n" if $hashh;
return undef;
}
}
print $hashh "\n" if $hashh;
close($loc)
unless defined $localfd;
$sock->close() or
return undef;
($remote) = $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
if ('STOU' eq uc $cmd);
return $remote;
}
sub port
{
@_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])';
my($ftp,$port) = @_;
my $ok;
delete ${*$ftp}{'net_ftp_intern_port'};
unless(defined $port)
{
# create a Listen socket at same address as the command socket
${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new(Listen => 5,
Proto => 'tcp',
);
my $listen = ${*$ftp}{'net_ftp_listen'};
my($myport, @myaddr) = ($listen->sockport, split(/\./,$ftp->sockhost));
$port = join(',', @myaddr, $myport >> 8, $myport & 0xff);
${*$ftp}{'net_ftp_intern_port'} = 1;
}
$ok = $ftp->_PORT($port);
${*$ftp}{'net_ftp_port'} = $port;
$ok;
}
sub ls { shift->_list_cmd("NLST",@_); }
sub dir { shift->_list_cmd("LIST",@_); }
sub pasv
{
@_ == 1 or croak 'usage: $ftp->pasv()';
my $ftp = shift;
delete ${*$ftp}{'net_ftp_intern_port'};
$ftp->_PASV && $ftp->message =~ /(\d+(,\d+)+)/
? ${*$ftp}{'net_ftp_pasv'} = $1
: undef;
}
sub unique_name
{
my $ftp = shift;
${*$ftp}{'net_ftp_unique'} || undef;
}
sub supported {
@_ == 2 or croak 'usage: $ftp->supported( CMD )';
my $ftp = shift;
my $cmd = uc shift;
my $hash = ${*$ftp}{'net_ftp_supported'} ||= {};
return $hash->{$cmd}
if exists $hash->{$cmd};
return $hash->{$cmd} = 0
unless $ftp->_HELP($cmd);
my $text = $ftp->message;
if($text =~ /following\s+commands/i) {
$text =~ s/^.*\n//;
$text =~ s/\n/ /sog;
while($text =~ /(\w+)([* ])/g) {
$hash->{"\U$1"} = $2 eq " " ? 1 : 0;
}
}
else {
$hash->{$cmd} = $text !~ /unimplemented/i;
}
$hash->{$cmd} ||= 0;
}
##
## Deprecated methods
##
sub lsl
{
carp "Use of Net::FTP::lsl deprecated, use 'dir'"
if $^W;
goto &dir;
}
sub authorise
{
carp "Use of Net::FTP::authorise deprecated, use 'authorize'"
if $^W;
goto &authorize;
}
##
## Private methods
##
sub _extract_path
{
my($ftp, $path) = @_;
# This tries to work both with and without the quote doubling
# convention (RFC 959 requires it, but the first 3 servers I checked
# didn't implement it). It will fail on a server which uses a quote in
# the message which isn't a part of or surrounding the path.
$ftp->ok &&
$ftp->message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &&
($path = $1) =~ s/\"\"/\"/g;
$path;
}
##
## Communication methods
##
sub _dataconn
{
my $ftp = shift;
my $data = undef;
my $pkg = "Net::FTP::" . $ftp->type;
eval "require " . $pkg;
$pkg =~ s/ /_/g;
delete ${*$ftp}{'net_ftp_dataconn'};
if(defined ${*$ftp}{'net_ftp_pasv'})
{
my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});
$data = $pkg->new(PeerAddr => join(".",@port[0..3]),
PeerPort => $port[4] * 256 + $port[5],
Proto => 'tcp'
);
}
elsif(defined ${*$ftp}{'net_ftp_listen'})
{
$data = ${*$ftp}{'net_ftp_listen'}->accept($pkg);
close(delete ${*$ftp}{'net_ftp_listen'});
}
if($data)
{
${*$data} = "";
$data->timeout($ftp->timeout);
${*$ftp}{'net_ftp_dataconn'} = $data;
${*$data}{'net_ftp_cmd'} = $ftp;
${*$data}{'net_ftp_blksize'} = ${*$ftp}{'net_ftp_blksize'};
}
$data;
}
sub _list_cmd
{
my $ftp = shift;
my $cmd = uc shift;
delete ${*$ftp}{'net_ftp_port'};
delete ${*$ftp}{'net_ftp_pasv'};
my $data = $ftp->_data_cmd($cmd,@_);
return
unless(defined $data);
require Net::FTP::A;
bless $data, "Net::FTP::A"; # Force ASCII mode
my $databuf = '';
my $buf = '';
my $blksize = ${*$ftp}{'net_ftp_blksize'};
while($data->read($databuf,$blksize)) {
$buf .= $databuf;
}
my $list = [ split(/\n/,$buf) ];
$data->close();
wantarray ? @{$list}
: $list;
}
sub _data_cmd
{
my $ftp = shift;
my $cmd = uc shift;
my $ok = 1;
my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
my $arg;
for $arg (@_) {
croak("Bad argument '$arg'\n")
if $arg =~ /[\r\n]/s;
}
if(${*$ftp}{'net_ftp_passive'} &&
!defined ${*$ftp}{'net_ftp_pasv'} &&
!defined ${*$ftp}{'net_ftp_port'})
{
my $data = undef;
$ok = defined $ftp->pasv;
$ok = $ftp->_REST($where)
if $ok && $where;
if($ok)
{
$ftp->command($cmd,@_);
$data = $ftp->_dataconn();
$ok = CMD_INFO == $ftp->response();
if($ok)
{
$data->reading
if $data && $cmd =~ /RETR|LIST|NLST/;
return $data
}
$data->_close
if $data;
}
return undef;
}
$ok = $ftp->port
unless (defined ${*$ftp}{'net_ftp_port'} ||
defined ${*$ftp}{'net_ftp_pasv'});
$ok = $ftp->_REST($where)
if $ok && $where;
return undef
unless $ok;
$ftp->command($cmd,@_);
return 1
if(defined ${*$ftp}{'net_ftp_pasv'});
$ok = CMD_INFO == $ftp->response();
return $ok
unless exists ${*$ftp}{'net_ftp_intern_port'};
if($ok) {
my $data = $ftp->_dataconn();
$data->reading
if $data && $cmd =~ /RETR|LIST|NLST/;
return $data;
}
close(delete ${*$ftp}{'net_ftp_listen'});
return undef;
}
##
## Over-ride methods (Net::Cmd)
##
sub debug_text { $_[2] =~ /^(pass|resp|acct)/i ? "$1 ....\n" : $_[2]; }
sub command
{
my $ftp = shift;
delete ${*$ftp}{'net_ftp_port'};
$ftp->SUPER::command(@_);
}
sub response
{
my $ftp = shift;
my $code = $ftp->SUPER::response();
delete ${*$ftp}{'net_ftp_pasv'}
if ($code != CMD_MORE && $code != CMD_INFO);
$code;
}
sub parse_response
{
return ($1, $2 eq "-")
if $_[1] =~ s/^(\d\d\d)(.?)//o;
my $ftp = shift;
# Darn MS FTP server is a load of CRAP !!!!
return ()
unless ${*$ftp}{'net_cmd_code'} + 0;
(${*$ftp}{'net_cmd_code'},1);
}
##
## Allow 2 servers to talk directly
##
sub pasv_xfer {
my($sftp,$sfile,$dftp,$dfile,$unique) = @_;
($dfile = $sfile) =~ s#.*/##
unless(defined $dfile);
my $port = $sftp->pasv or
return undef;
$dftp->port($port) or
return undef;
return undef
unless($unique ? $dftp->stou($dfile) : $dftp->stor($dfile));
unless($sftp->retr($sfile) && $sftp->response == CMD_INFO) {
$sftp->retr($sfile);
$dftp->abort;
$dftp->response();
return undef;
}
$dftp->pasv_wait($sftp);
}
sub pasv_wait
{
@_ == 2 or croak 'usage: $ftp->pasv_wait(NON_PASV_FTP)';
my($ftp, $non_pasv) = @_;
my($file,$rin,$rout);
vec($rin='',fileno($ftp),1) = 1;
select($rout=$rin, undef, undef, undef);
$ftp->response();
$non_pasv->response();
return undef
unless $ftp->ok() && $non_pasv->ok();
return $1
if $ftp->message =~ /unique file name:\s*(\S*)\s*\)/;
return $1
if $non_pasv->message =~ /unique file name:\s*(\S*)\s*\)/;
return 1;
}
sub cmd { shift->command(@_)->response() }
########################################
#
# RFC959 commands
#
sub _ABOR { shift->command("ABOR")->response() == CMD_OK }
sub _CDUP { shift->command("CDUP")->response() == CMD_OK }
sub _NOOP { shift->command("NOOP")->response() == CMD_OK }
sub _PASV { shift->command("PASV")->response() == CMD_OK }
sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
sub _DELE { shift->command("DELE",@_)->response() == CMD_OK }
sub _CWD { shift->command("CWD", @_)->response() == CMD_OK }
sub _PORT { shift->command("PORT",@_)->response() == CMD_OK }
sub _RMD { shift->command("RMD", @_)->response() == CMD_OK }
sub _MKD { shift->command("MKD", @_)->response() == CMD_OK }
sub _PWD { shift->command("PWD", @_)->response() == CMD_OK }
sub _TYPE { shift->command("TYPE",@_)->response() == CMD_OK }
sub _RNTO { shift->command("RNTO",@_)->response() == CMD_OK }
sub _RESP { shift->command("RESP",@_)->response() == CMD_OK }
sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK }
sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK }
sub _HELP { shift->command("HELP",@_)->response() == CMD_OK }
sub _STAT { shift->command("STAT",@_)->response() == CMD_OK }
sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO }
sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO }
sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO }
sub _RETR { shift->command("RETR",@_)->response() == CMD_INFO }
sub _STOR { shift->command("STOR",@_)->response() == CMD_INFO }
sub _STOU { shift->command("STOU",@_)->response() == CMD_INFO }
sub _RNFR { shift->command("RNFR",@_)->response() == CMD_MORE }
sub _REST { shift->command("REST",@_)->response() == CMD_MORE }
sub _USER { shift->command("user",@_)->response() } # A certain brain dead firewall :-)
sub _PASS { shift->command("PASS",@_)->response() }
sub _ACCT { shift->command("ACCT",@_)->response() }
sub _AUTH { shift->command("AUTH",@_)->response() }
sub _ALLO { shift->unsupported(@_) }
sub _SMNT { shift->unsupported(@_) }
sub _MODE { shift->unsupported(@_) }
sub _SYST { shift->unsupported(@_) }
sub _STRU { shift->unsupported(@_) }
sub _REIN { shift->unsupported(@_) }
1;
__END__
=head1 NAME
Net::FTP - FTP Client class
=head1 SYNOPSIS
use Net::FTP;
$ftp = Net::FTP->new("some.host.name", Debug => 0);
$ftp->login("anonymous",'me@here.there');
$ftp->cwd("/pub");
$ftp->get("that.file");
$ftp->quit;
=head1 DESCRIPTION
C is a class implementing a simple FTP client in Perl as
described in RFC959. It provides wrappers for a subset of the RFC959
commands.
=head1 OVERVIEW
FTP stands for File Transfer Protocol. It is a way of transferring
files between networked machines. The protocol defines a client
(whose commands are provided by this module) and a server (not
implemented in this module). Communication is always initiated by the
client, and the server responds with a message and a status code (and
sometimes with data).
The FTP protocol allows files to be sent to or fetched from the
server. Each transfer involves a B (on the client) and a
B (on the server). In this module, the same file name
will be used for both local and remote if only one is specified. This
means that transferring remote file C will try to put
that file in C locally, unless you specify a local file
name.
The protocol also defines several standard B which the
file can undergo during transfer. These are ASCII, EBCDIC, binary,
and byte. ASCII is the default type, and indicates that the sender of
files will translate the ends of lines to a standard representation
which the receiver will then translate back into their local
representation. EBCDIC indicates the file being transferred is in
EBCDIC format. Binary (also known as image) format sends the data as
a contiguous bit stream. Byte format transfers the data as bytes, the
values of which remain the same regardless of differences in byte size
between the two machines (in theory - in practice you should only use
this if you really know what you're doing).
=head1 CONSTRUCTOR
=over 4
=item new (HOST [,OPTIONS])
This is the constructor for a new Net::FTP object. C is the
name of the remote host to which a FTP connection is required.
C are passed in a hash like fashion, using key and value pairs.
Possible options are:
B - The name of a machine which acts as a FTP firewall. This can be
overridden by an environment variable C. If specified, and the
given host cannot be directly connected to, then the
connection is made to the firewall machine and the string C<@hostname> is
appended to the login identifier. This kind of setup is also refered to
as a ftp proxy.
B - This is the block size that Net::FTP will use when doing
transfers. (defaults to 10240)
B - The port number to connect to on the remote machine for the
FTP connection
B - Set a timeout value (defaults to 120)
B - debug level (see the debug method in L)
B - If set to a non-zero value then all data transfers will be done
using passive mode. This is not usually required except for some I
servers, and some firewall configurations. This can also be set by the
environment variable C.
B - If TRUE, print hash marks (#) on STDERR every 1024 bytes. This
simply invokes the C method for you, so that hash marks are displayed
for all transfers. You can, of course, call C explicitly whenever
you'd like.
If the constructor fails undef will be returned and an error message will
be in $@
=back
=head1 METHODS
Unless otherwise stated all methods return either a I or I
value, with I meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as I or an
empty list.
=over 4
=item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
Log into the remote FTP server with the given login information. If
no arguments are given then the C uses the C
package to lookup the login information for the connected host.
If no information is found then a login of I is used.
If no password is given and the login is I then the users
Email address will be used for a password.
If the connection is via a firewall then the C method will
be called with no arguments.
=item authorize ( [AUTH [, RESP]])
This is a protocol used by some firewall ftp proxies. It is used
to authorise the user to send data out. If both arguments are not specified
then C uses C to do a lookup.
=item site (ARGS)
Send a SITE command to the remote server and wait for a response.
Returns most significant digit of the response code.
=item type (TYPE [, ARGS])
This method will send the TYPE command to the remote FTP server
to change the type of data transfer. The return value is the previous
value.
=item ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])
Synonyms for C with the first arguments set correctly
B ebcdic and byte are not fully supported.
=item rename ( OLDNAME, NEWNAME )
Rename a file on the remote FTP server from C to C. This
is done by sending the RNFR and RNTO commands.
=item delete ( FILENAME )
Send a request to the server to delete C.
=item cwd ( [ DIR ] )
Attempt to change directory to the directory given in C<$dir>. If
C<$dir> is C<"..">, the FTP C command is used to attempt to
move up one directory. If no directory is given then an attempt is made
to change the directory to the root directory.
=item cdup ()
Change directory to the parent of the current directory.
=item pwd ()
Returns the full pathname of the current directory.
=item rmdir ( DIR )
Remove the directory with the name C.
=item mkdir ( DIR [, RECURSE ])
Create a new directory with the name C. If C is I then
C will attempt to create all the directories in the given path.
Returns the full pathname to the new directory.
=item ls ( [ DIR ] )
Get a directory listing of C, or the current directory.
In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.
=item dir ( [ DIR ] )
Get a directory listing of C, or the current directory in long format.
In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.
=item get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
Get C from the server and store locally. C may be
a filename or a filehandle. If not specified the the file will be stored in
the current directory with the same leafname as the remote file.
If C is given then the first C bytes of the file will
not be transfered, and the remaining bytes will be appended to
the local file if it already exists.
Returns C, or the generated local file name if C
is not given.
=item put ( LOCAL_FILE [, REMOTE_FILE ] )
Put a file on the remote server. C may be a name or a filehandle.
If C is a filehandle then C must be specified. If
C is not specified then the file will be stored in the current
directory with the same leafname as C.
Returns C, or the generated remote filename if C
is not given.
B: If for some reason the transfer does not complete and an error is
returned then the contents that had been transfered will not be remove
automatically.
=item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
Same as put but uses the C command.
Returns the name of the file on the server.
=item append ( LOCAL_FILE [, REMOTE_FILE ] )
Same as put but appends to the file on the remote server.
Returns C, or the generated remote filename if C
is not given.
=item unique_name ()
Returns the name of the last file stored on the server using the
C command.
=item mdtm ( FILE )
Returns the I of the given file
=item size ( FILE )
Returns the size in bytes for the given file as stored on the remote server.
B: The size reported is the size of the stored file on the remote server.
If the file is subsequently transfered from the server in ASCII mode
and the remote server and local machine have different ideas about
"End Of Line" then the size of file on the local machine after transfer
may be different.
=item supported ( CMD )
Returns TRUE if the remote server supports the given command.
=item hash ( [FILEHANDLE_GLOB_REF],[ BYTES_PER_HASH_MARK] )
Called without parameters, or with the first argument false, hash marks
are suppressed. If the first argument is true but not a reference to a
file handle glob, then \*STDERR is used. The second argument is the number
of bytes per hash mark printed, and defaults to 1024. In all cases the
return value is a reference to an array of two: the filehandle glob reference
and the bytes per hash mark.
=back
The following methods can return different results depending on
how they are called. If the user explicitly calls either
of the C or C methods then these methods will
return a I or I value. If the user does not
call either of these methods then the result will be a
reference to a C based object.
=over 4
=item nlst ( [ DIR ] )
Send a C command to the server, with an optional parameter.
=item list ( [ DIR ] )
Same as C but using the C command
=item retr ( FILE )
Begin the retrieval of a file called C from the remote server.
=item stor ( FILE )
Tell the server that you wish to store a file. C is the
name of the new file that should be created.
=item stou ( FILE )
Same as C but using the C command. The name of the unique
file which was created on the server will be available via the C
method after the data connection has been closed.
=item appe ( FILE )
Tell the server that we want to append some data to the end of a file
called C. If this file does not exist then create it.
=back
If for some reason you want to have complete control over the data connection,
this includes generating it and calling the C method when required,
then the user can use these methods to do so.
However calling these methods only affects the use of the methods above that
can return a data connection. They have no effect on methods C, C,
C and those that do not require data connections.
=over 4
=item port ( [ PORT ] )
Send a C command to the server. If C is specified then it is sent
to the server. If not the a listen socket is created and the correct information
sent to the server.
=item pasv ()
Tell the server to go into passive mode. Returns the text that represents the
port on which the server is listening, this text is in a suitable form to
sent to another ftp server using the C method.
=back
The following methods can be used to transfer files between two remote
servers, providing that these two servers can connect directly to each other.
=over 4
=item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
This method will do a file transfer between two remote ftp servers. If
C is omitted then the leaf name of C will be used.
=item pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
Like C but the file is stored on the remote server using
the STOU command.
=item pasv_wait ( NON_PASV_SERVER )
This method can be used to wait for a transfer to complete between a passive
server and a non-passive server. The method should be called on the passive
server with the C object for the non-passive server passed as an
argument.
=item abort ()
Abort the current data transfer.
=item quit ()
Send the QUIT command to the remote FTP server and close the socket connection.
=back
=head2 Methods for the adventurous
C inherits from C so methods defined in C may
be used to send commands to the remote FTP server.
=over 4
=item quot (CMD [,ARGS])
Send a command, that Net::FTP does not directly support, to the remote
server and wait for a response.
Returns most significant digit of the response code.
B This call should only be used on commands that do not require
data connections. Misuse of this method can hang the connection.
=back
=head1 THE dataconn CLASS
Some of the methods defined in C return an object which will
be derived from this class.The dataconn class itself is derived from
the C class, so any normal IO operations can be performed.
However the following methods are defined in the dataconn class and IO should
be performed using these.
=over 4
=item read ( BUFFER, SIZE [, TIMEOUT ] )
Read C bytes of data from the server and place it into C, also
performing any translation necessary. C is optional, if not
given the the timeout value from the command connection will be used.
Returns the number of bytes read before any translation.
=item write ( BUFFER, SIZE [, TIMEOUT ] )
Write C bytes of data from C to the server, also
performing any translation necessary. C is optional, if not
given the the timeout value from the command connection will be used.
Returns the number of bytes written before any translation.
=item abort ()
Abort the current data transfer.
=item close ()
Close the data connection and get a response from the FTP server. Returns
I if the connection was closed successfully and the first digit of
the response from the server was a '2'.
=back
=head1 UNIMPLEMENTED
The following RFC959 commands have not been implemented:
=over 4
=item B
Allocates storage for the file to be transferred.
=item B
Mount a different file system structure without changing login or
accounting information.
=item B
Ask the server for "helpful information" (that's what the RFC says) on
the commands it accepts.
=item B
Specifies transfer mode (stream, block or compressed) for file to be
transferred.
=item B
Request remote server system identification.
=item B
Request remote server status.
=item B
Specifies file structure for file to be transferred.
=item B
Reinitialize the connection, flushing all I/O and account information.
=back
=head1 REPORTING BUGS
When reporting bugs/problems please include as much information as possible.
It may be difficult for me to reproduce the problem as almost every setup
is different.
A small script which yields the problem will probably be of help. It would
also be useful if this script was run with the extra options C 1>
passed to the constructor, and the output sent with the bug report. If you
cannot include a small script then please include a Debug trace from a
run of your program which does yield the problem.
=head1 AUTHOR
Graham Barr
=head1 SEE ALSO
L
L
ftp(1), ftpd(8), RFC 959
http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
=head1 CREDITS
Henry Gabryjelski - for the suggestion of creating directories
recursively.
Nathan Torkington - for some input on the documentation.
Roderick Schertler - for various inputs
=head1 COPYRIGHT
Copyright (c) 1995-1998 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
WFTP_FILE_END: www_ftp/Net/FTP.pm
WFTP_FILE_START: www_ftp/Net/Netrc.pm
# Net::Netrc.pm
#
# Copyright (c) 1995-1998 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Net::Netrc;
use Carp;
use strict;
use FileHandle;
use vars qw($VERSION);
$VERSION = "2.10"; # $Id: //depot/libnet/Net/Netrc.pm#4$
my %netrc = ();
sub _readrc
{
my $host = shift;
my($home,$file);
if($^O eq "MacOS") {
$home = $ENV{HOME} || `pwd`;
chomp($home);
$file = ($home =~ /:$/ ? $home . "netrc" : $home . ":netrc");
} else {
# Some OS's don't have `getpwuid', so we default to $ENV{HOME}
$home = eval { (getpwuid($>))[7] } || $ENV{HOME};
$file = $home . "/.netrc";
}
my($login,$pass,$acct) = (undef,undef,undef);
my $fh;
local $_;
$netrc{default} = undef;
# OS/2 and Win32 do not handle stat in a way compatable with this check :-(
unless($^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'MacOS')
{
my @stat = stat($file);
if(@stat)
{
if($stat[2] & 077)
{
carp "Bad permissions: $file";
return;
}
if($stat[4] != $<)
{
carp "Not owner: $file";
return;
}
}
}
if($fh = FileHandle->new($file,"r"))
{
my($mach,$macdef,$tok,@tok) = (0,0);
while(<$fh>)
{
undef $macdef if /\A\n\Z/;
if($macdef)
{
push(@$macdef,$_);
next;
}
s/^\s*//;
chomp;
push(@tok, $+)
while(length && s/^("([^"]*)"|(\S+))\s*//);
TOKEN:
while(@tok)
{
if($tok[0] eq "default")
{
shift(@tok);
$mach = bless {};
$netrc{default} = [$mach];
next TOKEN;
}
last TOKEN
unless @tok > 1;
$tok = shift(@tok);
if($tok eq "machine")
{
my $host = shift @tok;
$mach = bless {machine => $host};
$netrc{$host} = []
unless exists($netrc{$host});
push(@{$netrc{$host}}, $mach);
}
elsif($tok =~ /^(login|password|account)$/)
{
next TOKEN unless $mach;
my $value = shift @tok;
# Following line added by rmerrell to remove '/' escape char in .netrc
$value =~ s/\/\\/\\/g;
$mach->{$1} = $value;
}
elsif($tok eq "macdef")
{
next TOKEN unless $mach;
my $value = shift @tok;
$mach->{macdef} = {}
unless exists $mach->{macdef};
$macdef = $mach->{machdef}{$value} = [];
}
}
}
$fh->close();
}
}
sub lookup
{
my($pkg,$mach,$login) = @_;
_readrc()
unless exists $netrc{default};
$mach ||= 'default';
undef $login
if $mach eq 'default';
if(exists $netrc{$mach})
{
if(defined $login)
{
my $m;
foreach $m (@{$netrc{$mach}})
{
return $m
if(exists $m->{login} && $m->{login} eq $login);
}
return undef;
}
return $netrc{$mach}->[0]
}
return $netrc{default}->[0]
if defined $netrc{default};
return undef;
}
sub login
{
my $me = shift;
exists $me->{login}
? $me->{login}
: undef;
}
sub account
{
my $me = shift;
exists $me->{account}
? $me->{account}
: undef;
}
sub password
{
my $me = shift;
exists $me->{password}
? $me->{password}
: undef;
}
sub lpa
{
my $me = shift;
($me->login, $me->password, $me->account);
}
1;
__END__
=head1 NAME
Net::Netrc - OO interface to users netrc file
=head1 SYNOPSIS
use Net::Netrc;
$mach = Net::Netrc->lookup('some.machine');
$login = $mach->login;
($login, $password, $account) = $mach->lpa;
=head1 DESCRIPTION
C is a class implementing a simple interface to the .netrc file
used as by the ftp program.
C also implements security checks just like the ftp program,
these checks are, first that the .netrc file must be owned by the user and
second the ownership permissions should be such that only the owner has
read and write access. If these conditions are not met then a warning is
output and the .netrc file is not read.
=head1 THE .netrc FILE
The .netrc file contains login and initialization information used by the
auto-login process. It resides in the user's home directory. The following
tokens are recognized; they may be separated by spaces, tabs, or new-lines:
=over 4
=item machine name
Identify a remote machine name. The auto-login process searches
the .netrc file for a machine token that matches the remote machine
specified. Once a match is made, the subsequent .netrc tokens
are processed, stopping when the end of file is reached or an-
other machine or a default token is encountered.
=item default
This is the same as machine name except that default matches
any name. There can be only one default token, and it must be
after all machine tokens. This is normally used as:
default login anonymous password user@site
thereby giving the user automatic anonymous login to machines
not specified in .netrc.
=item login name
Identify a user on the remote machine. If this token is present,
the auto-login process will initiate a login using the
specified name.
=item password string
Supply a password. If this token is present, the auto-login
process will supply the specified string if the remote server
requires a password as part of the login process.
=item account string
Supply an additional account password. If this token is present,
the auto-login process will supply the specified string
if the remote server requires an additional account password.
=item macdef name
Define a macro. C only parses this field to be compatible
with I.
=back
=head1 CONSTRUCTOR
The constructor for a C object is not called new as it does not
really create a new object. But instead is called C as this is
essentially what it does.
=over 4
=item lookup ( MACHINE [, LOGIN ])
Lookup and return a reference to the entry for C. If C is given
then the entry returned will have the given login. If C is not given then
the first entry in the .netrc file for C will be returned.
If a matching entry cannot be found, and a default entry exists, then a
reference to the default entry is returned.
=back
=head1 METHODS
=over 4
=item login ()
Return the login id for the netrc entry
=item password ()
Return the password for the netrc entry
=item account ()
Return the account information for the netrc entry
=item lpa ()
Return a list of login, password and account information fir the netrc entry
=back
=head1 AUTHOR
Graham Barr
=head1 SEE ALSO
L
L
=head1 COPYRIGHT
Copyright (c) 1995-1998 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
WFTP_FILE_END: www_ftp/Net/Netrc.pm
WFTP_FILE_START: www_ftp/Net/NNTP.pm
# Net::NNTP.pm
#
# Copyright (c) 1995-1997 Graham Barr . All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
package Net::NNTP;
use strict;
use vars qw(@ISA $VERSION $debug);
use IO::Socket;
use Net::Cmd;
use Carp;
use Time::Local;
use Net::Config;
$VERSION = "2.19"; # $Id: //depot/libnet/Net/NNTP.pm#8$
@ISA = qw(Net::Cmd IO::Socket::INET);
sub new
{
my $self = shift;
my $type = ref($self) || $self;
my $host = shift if @_ % 2;
my %arg = @_;
my $obj;
$host ||= $ENV{NNTPSERVER} || $ENV{NEWSHOST};
my $hosts = defined $host ? [ $host ] : $NetConfig{nntp_hosts};
@{$hosts} = qw(news)
unless @{$hosts};
my $h;
foreach $h (@{$hosts})
{
$obj = $type->SUPER::new(PeerAddr => ($host = $h),
PeerPort => $arg{Port} || 'nntp(119)',
Proto => 'tcp',
Timeout => defined $arg{Timeout}
? $arg{Timeout}
: 120
) and last;
}
return undef
unless defined $obj;
${*$obj}{'net_nntp_host'} = $host;
$obj->autoflush(1);
$obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
unless ($obj->response() == CMD_OK)
{
$obj->close;
return undef;
}
my $c = $obj->code;
my @m = $obj->message;
unless(exists $arg{Reader} && $arg{Reader} == 0) {
# if server is INN and we have transfer rights the we are currently
# talking to innd not nnrpd
if($obj->reader)
{
# If reader suceeds the we need to consider this code to determine postok
$c = $obj->code;
}
else
{
# I want to ignore this failure, so restore the previous status.
$obj->set_status($c,\@m);
}
}
${*$obj}{'net_nntp_post'} = $c == 200 ? 1 : 0;
$obj;
}
sub debug_text
{
my $nntp = shift;
my $inout = shift;
my $text = shift;
if(($nntp->code == 350 && $text =~ /^(\S+)/)
|| ($text =~ /^(authinfo\s+pass)/io))
{
$text = "$1 ....\n"
}
$text;
}
sub postok
{
@_ == 1 or croak 'usage: $nntp->postok()';
my $nntp = shift;
${*$nntp}{'net_nntp_post'} || 0;
}
sub article
{
@_ >= 1 && @_ <= 3 or croak 'usage: $nntp->article( [ MSGID ], [ FH ] )';
my $nntp = shift;
my @fh;
@fh = (pop) if @_ == 2 || (@_ && ref($_[0]) || ref(\$_[0]) eq 'GLOB');
$nntp->_ARTICLE(@_)
? $nntp->read_until_dot(@fh)
: undef;
}
sub authinfo
{
@_ == 3 or croak 'usage: $nntp->authinfo( USER, PASS )';
my($nntp,$user,$pass) = @_;
$nntp->_AUTHINFO("USER",$user) == CMD_MORE
&& $nntp->_AUTHINFO("PASS",$pass) == CMD_OK;
}
sub authinfo_simple
{
@_ == 3 or croak 'usage: $nntp->authinfo( USER, PASS )';
my($nntp,$user,$pass) = @_;
$nntp->_AUTHINFO('SIMPLE') == CMD_MORE
&& $nntp->command($user,$pass)->response == CMD_OK;
}
sub body
{
@_ >= 1 && @_ <= 3 or croak 'usage: $nntp->body( [ MSGID ], [ FH ] )';
my $nntp = shift;
my @fh;
@fh = (pop) if @_ == 2 || (@_ && ref($_[0]) || ref(\$_[0]) eq 'GLOB');
$nntp->_BODY(@_)
? $nntp->read_until_dot(@fh)
: undef;
}
sub head
{
@_ >= 1 && @_ <= 3 or croak 'usage: $nntp->head( [ MSGID ], [ FH ] )';
my $nntp = shift;
my @fh;
@fh = (pop) if @_ == 2 || (@_ && ref($_[0]) || ref(\$_[0]) eq 'GLOB');
$nntp->_HEAD(@_)
? $nntp->read_until_dot(@fh)
: undef;
}
sub nntpstat
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->nntpstat( [ MSGID ] )';
my $nntp = shift;
$nntp->_STAT(@_) && $nntp->message =~ /(<[^>]+>)/o
? $1
: undef;
}
sub group
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->group( [ GROUP ] )';
my $nntp = shift;
my $grp = ${*$nntp}{'net_nntp_group'} || undef;
return $grp
unless(@_ || wantarray);
my $newgrp = shift;
return wantarray ? () : undef
unless $nntp->_GROUP($newgrp || $grp || "")
&& $nntp->message =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/;
my($count,$first,$last,$group) = ($1,$2,$3,$4);
# group may be replied as '(current group)'
$group = ${*$nntp}{'net_nntp_group'}
if $group =~ /\(/;
${*$nntp}{'net_nntp_group'} = $group;
wantarray
? ($count,$first,$last,$group)
: $group;
}
sub help
{
@_ == 1 or croak 'usage: $nntp->help()';
my $nntp = shift;
$nntp->_HELP
? $nntp->read_until_dot
: undef;
}
sub ihave
{
@_ >= 2 or croak 'usage: $nntp->ihave( MESSAGE-ID [, MESSAGE ])';
my $nntp = shift;
my $mid = shift;
$nntp->_IHAVE($mid) && $nntp->datasend(@_)
? @_ == 0 || $nntp->dataend
: undef;
}
sub last
{
@_ == 1 or croak 'usage: $nntp->last()';
my $nntp = shift;
$nntp->_LAST && $nntp->message =~ /(<[^>]+>)/o
? $1
: undef;
}
sub list
{
@_ == 1 or croak 'usage: $nntp->list()';
my $nntp = shift;
$nntp->_LIST
? $nntp->_grouplist
: undef;
}
sub newgroups
{
@_ >= 2 or croak 'usage: $nntp->newgroups( SINCE [, DISTRIBUTIONS ])';
my $nntp = shift;
my $time = _timestr(shift);
my $dist = shift || "";
$dist = join(",", @{$dist})
if ref($dist);
$nntp->_NEWGROUPS($time,$dist)
? $nntp->_grouplist
: undef;
}
sub newnews
{
@_ >= 2 && @_ <= 4 or
croak 'usage: $nntp->newnews( SINCE [, GROUPS [, DISTRIBUTIONS ]])';
my $nntp = shift;
my $time = _timestr(shift);
my $grp = @_ ? shift : $nntp->group;
my $dist = shift || "";
$grp ||= "*";
$grp = join(",", @{$grp})
if ref($grp);
$dist = join(",", @{$dist})
if ref($dist);
$nntp->_NEWNEWS($grp,$time,$dist)
? $nntp->_articlelist
: undef;
}
sub next
{
@_ == 1 or croak 'usage: $nntp->next()';
my $nntp = shift;
$nntp->_NEXT && $nntp->message =~ /(<[^>]+>)/o
? $1
: undef;
}
sub post
{
@_ >= 1 or croak 'usage: $nntp->post( [ MESSAGE ] )';
my $nntp = shift;
$nntp->_POST() && $nntp->datasend(@_)
? @_ == 0 || $nntp->dataend
: undef;
}
sub quit
{
@_ == 1 or croak 'usage: $nntp->quit()';
my $nntp = shift;
$nntp->_QUIT;
$nntp->close;
}
sub slave
{
@_ == 1 or croak 'usage: $nntp->slave()';
my $nntp = shift;
$nntp->_SLAVE;
}
##
## The following methods are not implemented by all servers
##
sub active
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->active( [ PATTERN ] )';
my $nntp = shift;
$nntp->_LIST('ACTIVE',@_)
? $nntp->_grouplist
: undef;
}
sub active_times
{
@_ == 1 or croak 'usage: $nntp->active_times()';
my $nntp = shift;
$nntp->_LIST('ACTIVE.TIMES')
? $nntp->_grouplist
: undef;
}
sub distributions
{
@_ == 1 or croak 'usage: $nntp->distributions()';
my $nntp = shift;
$nntp->_LIST('DISTRIBUTIONS')
? $nntp->_description
: undef;
}
sub distribution_patterns
{
@_ == 1 or croak 'usage: $nntp->distributions()';
my $nntp = shift;
my $arr;
local $_;
$nntp->_LIST('DISTRIB.PATS') && ($arr = $nntp->read_until_dot)
? [grep { /^\d/ && (chomp, $_ = [ split /:/ ]) } @$arr]
: undef;
}
sub newsgroups
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->newsgroups( [ PATTERN ] )';
my $nntp = shift;
$nntp->_LIST('NEWSGROUPS',@_)
? $nntp->_description
: undef;
}
sub overview_fmt
{
@_ == 1 or croak 'usage: $nntp->overview_fmt()';
my $nntp = shift;
$nntp->_LIST('OVERVIEW.FMT')
? $nntp->_articlelist
: undef;
}
sub subscriptions
{
@_ == 1 or croak 'usage: $nntp->subscriptions()';
my $nntp = shift;
$nntp->_LIST('SUBSCRIPTIONS')
? $nntp->_articlelist
: undef;
}
sub listgroup
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->listgroup( [ GROUP ] )';
my $nntp = shift;
$nntp->_LISTGROUP(@_)
? $nntp->_articlelist
: undef;
}
sub reader
{
@_ == 1 or croak 'usage: $nntp->reader()';
my $nntp = shift;
$nntp->_MODE('READER');
}
sub xgtitle
{
@_ == 1 || @_ == 2 or croak 'usage: $nntp->xgtitle( [ PATTERN ] )';
my $nntp = shift;
$nntp->_XGTITLE(@_)
? $nntp->_description
: undef;
}
sub xhdr
{
@_ >= 2 && @_ <= 4 or croak 'usage: $nntp->xhdr( HEADER, [ MESSAGE-SPEC ] )';
my $nntp = shift;
my $hdr = shift;
my $arg = _msg_arg(@_);
$nntp->_XHDR($hdr, $arg)
? $nntp->_description
: undef;
}
sub xover
{
@_ == 2 || @_ == 3 or croak 'usage: $nntp->xover( MESSAGE-SPEC )';
my $nntp = shift;
my $arg = _msg_arg(@_);
$nntp->_XOVER($arg)
? $nntp->_fieldlist
: undef;
}
sub xpat
{
@_ == 4 || @_ == 5 or croak '$nntp->xpat( HEADER, PATTERN, MESSAGE-SPEC )';
my $nntp = shift;
my $hdr = shift;
my $pat = shift;
my $arg = _msg_arg(@_);
$pat = join(" ", @$pat)
if ref($pat);
$nntp->_XPAT($hdr,$arg,$pat)
? $nntp->_description
: undef;
}
sub xpath
{
@_ == 2 or croak 'usage: $nntp->xpath( MESSAGE-ID )';
my($nntp,$mid) = @_;
return undef
unless $nntp->_XPATH($mid);
my $m; ($m = $nntp->message) =~ s/^\d+\s+//o;
my @p = split /\s+/, $m;
wantarray ? @p : $p[0];
}
sub xrover
{
@_ == 2 || @_ == 3 or croak 'usage: $nntp->xrover( MESSAGE-SPEC )';
my $nntp = shift;
my $arg = _msg_arg(@_);
$nntp->_XROVER($arg)
? $nntp->_description
: undef;
}
sub date
{
@_ == 1 or croak 'usage: $nntp->date()';
my $nntp = shift;
$nntp->_DATE && $nntp->message =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
? timegm($6,$5,$4,$3,$2-1,$1 - 1900)
: undef;
}
##
## Private subroutines
##
sub _msg_arg
{
my $spec = shift;
my $arg = "";
if(@_)
{
carp "Depriciated passing of two message numbers, "
. "pass a reference"
if $^W;
$spec = [ $spec, $_[0] ];
}
if(defined $spec)
{
if(ref($spec))
{
$arg = $spec->[0] . "-";
$arg .= $spec->[1]
if defined $spec->[1] && $spec->[1] > $spec->[0];
}
else
{
$arg = $spec;
}
}
$arg;
}
sub _timestr
{
my $time = shift;
my @g = reverse((gmtime($time))[0..5]);
$g[1] += 1;
$g[0] %= 100;
sprintf "%02d%02d%02d %02d%02d%02d GMT", @g;
}
sub _grouplist
{
my $nntp = shift;
my $arr = $nntp->read_until_dot or
return undef;
my $hash = {};
my $ln;
foreach $ln (@$arr)
{
my @a = split(/[\s\n]+/,$ln);
$hash->{$a[0]} = [ @a[1,2,3] ];
}
$hash;
}
sub _fieldlist
{
my $nntp = shift;
my $arr = $nntp->read_until_dot or
return undef;
my $hash = {};
my $ln;
foreach $ln (@$arr)
{
my @a = split(/[\t\n]/,$ln);
my $m = shift @a;
$hash->{$m} = [ @a ];
}
$hash;
}
sub _articlelist
{
my $nntp = shift;
my $arr = $nntp->read_until_dot;
chomp(@$arr)
if $arr;
$arr;
}
sub _description
{
my $nntp = shift;
my $arr = $nntp->read_until_dot or
return undef;
my $hash = {};
my $ln;
foreach $ln (@$arr)
{
chomp($ln);
$hash->{$1} = $ln
if $ln =~ s/^\s*(\S+)\s*//o;
}
$hash;
}
##
## The commands
##
sub _ARTICLE { shift->command('ARTICLE',@_)->response == CMD_OK }
sub _AUTHINFO { shift->command('AUTHINFO',@_)->response }
sub _BODY { shift->command('BODY',@_)->response == CMD_OK }
sub _DATE { shift->command('DATE')->response == CMD_INFO }
sub _GROUP { shift->command('GROUP',@_)->response == CMD_OK }
sub _HEAD { shift->command('HEAD',@_)->response == CMD_OK }
sub _HELP { shift->command('HELP',@_)->response == CMD_INFO }
sub _IHAVE { shift->command('IHAVE',@_)->response == CMD_MORE }
sub _LAST { shift->command('LAST')->response == CMD_OK }
sub _LIST { shift->command('LIST',@_)->response == CMD_OK }
sub _LISTGROUP { shift->command('LISTGROUP',@_)->response == CMD_OK }
sub _NEWGROUPS { shift->command('NEWGROUPS',@_)->response == CMD_OK }
sub _NEWNEWS { shift->command('NEWNEWS',@_)->response == CMD_OK }
sub _NEXT { shift->command('NEXT')->response == CMD_OK }
sub _POST { shift->command('POST',@_)->response == CMD_MORE }
sub _QUIT { shift->command('QUIT',@_)->response == CMD_OK }
sub _SLAVE { shift->command('SLAVE',@_)->response == CMD_OK }
sub _STAT { shift->command('STAT',@_)->response == CMD_OK }
sub _MODE { shift->command('MODE',@_)->response == CMD_OK }
sub _XGTITLE { shift->command('XGTITLE',@_)->response == CMD_OK }
sub _XHDR { shift->command('XHDR',@_)->response == CMD_OK }
sub _XPAT { shift->command('XPAT',@_)->response == CMD_OK }
sub _XPATH { shift->command('XPATH',@_)->response == CMD_OK }
sub _XOVER { shift->command('XOVER',@_)->response == CMD_OK }
sub _XROVER { shift->command('XROVER',@_)->response == CMD_OK }
sub _XTHREAD { shift->unsupported }
sub _XSEARCH { shift->unsupported }
sub _XINDEX { shift->unsupported }
##
## IO/perl methods
##
sub DESTROY
{
my $nntp = shift;
defined(fileno($nntp)) && $nntp->quit
}
1;
__END__
=head1 NAME
Net::NNTP - NNTP Client class
=head1 SYNOPSIS
use Net::NNTP;
$nntp = Net::NNTP->new("some.host.name");
$nntp->quit;
=head1 DESCRIPTION
C is a class implementing a simple NNTP client in Perl as described
in RFC977. C inherits its communication methods from C
=head1 CONSTRUCTOR
=over 4
=item new ( [ HOST ] [, OPTIONS ])
This is the constructor for a new Net::NNTP object. C is the
name of the remote host to which a NNTP connection is required. If not
given two environment variables are checked, first C then
C, then C is checked, and if a host is not found
then C is used.
C are passed in a hash like fashion, using key and value pairs.
Possible options are:
B - Maximum time, in seconds, to wait for a response from the
NNTP server, a value of zero will cause all IO operations to block.
(default: 120)
B - Enable the printing of debugging information to STDERR
B - If the remote server is INN then initially the connection
will be to nnrpd, by default C will issue a C command
so that the remote server becomes innd. If the C option is given
with a value of zero, then this command will not be sent and the
connection will be left talking to nnrpd.
=back
=head1 METHODS
Unless otherwise stated all methods return either a I or I
value, with I meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as I or an
empty list.
=over 4
=item article ( [ MSGID|MSGNUM ], [FH] )
Retrieve the header, a blank line, then the body (text) of the
specified article.
If C is specified then it is expected to be a valid filehandle
and the result will be printed to it, on sucess a true value will be
returned. If C is not specified then the return value, on sucess,
will be a reference to an array containg the article requested, each
entry in the array will contain one line of the article.
If no arguments are passed then the current article in the currently
selected newsgroup is fetched.
C is a numeric id of an article in the current newsgroup, and
will change the current article pointer. C is the message id of
an article as shown in that article's header. It is anticipated that the
client will obtain the C from a list provided by the C
command, from references contained within another article, or from the
message-id provided in the response to some other commands.
If there is an error then C will be returned.
=item body ( [ MSGID|MSGNUM ], [FH] )
Like C but only fetches the body of the article.
=item head ( [ MSGID|MSGNUM ], [FH] )
Like C but only fetches the headers for the article.
=item nntpstat ( [ MSGID|MSGNUM ] )
The C command is similar to the C command except that no
text is returned. When selecting by message number within a group,
the C command serves to set the "current article pointer" without
sending text.
Using the C command to
select by message-id is valid but of questionable value, since a
selection by message-id does B alter the "current article pointer".
Returns the message-id of the "current article".
=item group ( [ GROUP ] )
Set and/or get the current group. If C is not given then information
is returned on the current group.
In a scalar context it returns the group name.
In an array context the return value is a list containing, the number
of articles in the group, the number of the first article, the number
of the last article and the group name.
=item ihave ( MSGID [, MESSAGE ])
The C command informs the server that the client has an article
whose id is C. If the server desires a copy of that
article, and C has been given the it will be sent.
Returns I if the server desires the article and C was
successfully sent,if specified.
If C is not specified then the message must be sent using the
C and C methods from L
C can be either an array of lines or a reference to an array.
=item last ()
Set the "current article pointer" to the previous article in the current
newsgroup.
Returns the message-id of the article.
=item date ()
Returns the date on the remote server. This date will be in a UNIX time
format (seconds since 1970)
=item postok ()
C will return I if the servers initial response indicated
that it will allow posting.
=item authinfo ( USER, PASS )
=item list ()
Obtain information about all the active newsgroups. The results is a reference
to a hash where the key is a group name and each value is a reference to an
array. The elements in this array are:- the first article number in the group,
the last article number in the group and any information flags about the group.
=item newgroups ( SINCE [, DISTRIBUTIONS ])
C is a time value and C is either a distribution
pattern or a reference to a list of distribution patterns.
The result is the same as C, but the
groups return will be limited to those created after C