package LWP::Protocol::ftp;
# Implementation of the ftp protocol (RFC 959). We let the Net::FTP
# package do all the dirty work.
use Carp ();
use HTTP::Status ();
use HTTP::Negotiate ();
use HTTP::Response ();
use LWP::MediaTypes ();
use File::Listing ();
require LWP::Protocol;
@ISA = qw(LWP::Protocol);
use strict;
eval {
package LWP::Protocol::MyFTP;
require Net::FTP;
Net::FTP->require_version(2.00);
use vars qw(@ISA);
@ISA=qw(Net::FTP);
sub new {
my $class = shift;
LWP::Debug::trace('()');
my $self = $class->SUPER::new(@_) || return undef;
my $mess = $self->message; # welcome message
LWP::Debug::debug($mess);
$mess =~ s|\n.*||s; # only first line left
$mess =~ s|\s*ready\.?$||;
# Make the version number more HTTP like
$mess =~ s|\s*\(Version\s*|/| and $mess =~ s|\)$||;
${*$self}{myftp_server} = $mess;
#$response->header("Server", $mess);
$self;
}
sub http_server {
my $self = shift;
${*$self}{myftp_server};
}
sub home {
my $self = shift;
my $old = ${*$self}{myftp_home};
if (@_) {
${*$self}{myftp_home} = shift;
}
$old;
}
sub go_home {
LWP::Debug::trace('');
my $self = shift;
$self->cwd(${*$self}{myftp_home});
}
sub request_count {
my $self = shift;
++${*$self}{myftp_reqcount};
}
sub ping {
LWP::Debug::trace('');
my $self = shift;
return $self->go_home;
}
};
my $init_failed = $@;
sub _connect {
my($self, $host, $port, $user, $account, $password, $timeout) = @_;
my $key;
my $conn_cache = $self->{ua}{conn_cache};
if ($conn_cache) {
$key = "$host:$port:$user";
$key .= ":$account" if defined($account);
if (my $ftp = $conn_cache->withdraw("ftp", $key)) {
if ($ftp->ping) {
LWP::Debug::debug('Reusing old connection');
# save it again
$conn_cache->deposit("ftp", $key, $ftp);
return $ftp;
}
}
}
# try to make a connection
my $ftp = LWP::Protocol::MyFTP->new($host,
Port => $port,
=1= |