$FTP_PASSIVE $TIMEOUT $DEBUG $WARN
];
-$VERSION = '0.20';
+$VERSION = '0.21_01';
$VERSION = eval $VERSION; # avoid warnings with development releases
$PREFER_BIN = 0; # XXX TODO implement
$FROM_EMAIL = 'File-Fetch@example.com';
### methods available to fetch the file depending on the scheme
$METHODS = {
- http => [ qw|lwp wget curl lftp lynx| ],
+ http => [ qw|lwp wget curl lftp lynx iosock| ],
ftp => [ qw|lwp netftp wget curl lftp ncftp ftp| ],
file => [ qw|lwp lftp file| ],
rsync => [ qw|rsync| ]
}
}
+### Simple IO::Socket::INET fetching ###
+sub _iosock_fetch {
+ my $self = shift;
+ my %hash = @_;
+
+ my ($to);
+ my $tmpl = {
+ to => { required => 1, store => \$to }
+ };
+ check( $tmpl, \%hash ) or return;
+
+ my $use_list = {
+ 'IO::Socket::INET' => '0.0',
+ 'IO::Select' => '0.0',
+ };
+
+ if( can_load(modules => $use_list) ) {
+ my $sock = IO::Socket::INET->new(
+ PeerHost => $self->host,
+ ( $self->host =~ /:/ ? () : ( PeerPort => 80 ) ),
+ );
+
+ unless ( $sock ) {
+ return $self->_error(loc("Could not open socket to '%1', '%2'",$self->host,$!));
+ }
+
+ my $fh = FileHandle->new;
+
+ # Check open()
+
+ unless ( $fh->open($to,'>') ) {
+ return $self->_error(loc(
+ "Could not open '%1' for writing: %2",$to,$!));
+ }
+
+ $sock->send( "GET $self->path HTTP/1.0\x0d\x0aHost: $self->host\x0d\x0a\x0d\x0a" );
+
+ my $select = IO::Select->new( $sock );
+
+ my $resp = '';
+ my $normal = 0;
+ while ( $select->can_read( $TIMEOUT || 60 ) ) {
+ my $ret = $sock->sysread( $resp, 4096, length($resp) );
+ if ( !defined $ret or $ret == 0 ) {
+ $select->remove( $sock );
+ $normal++;
+ }
+ }
+ close $sock;
+
+ unless ( $normal ) {
+ return $self->_error(loc("Socket timed out after '%1' seconds", ( $TIMEOUT || 60 )));
+ }
+
+ print $fh +($resp =~ m/\x0d\x0a\x0d\x0a(.*)$/s )[0];
+ close $fh;
+ return $to;
+
+ } else {
+ $METHOD_FAIL->{'iosock'} = 1;
+ return;
+ }
+}
+
### Net::FTP fetching
sub _netftp_fetch {
my $self = shift;
for what schemes, if available:
file => LWP, lftp, file
- http => LWP, wget, curl, lftp, lynx
+ http => LWP, wget, curl, lftp, lynx, iosock
ftp => LWP, Net::FTP, wget, curl, lftp, ncftp, ftp
rsync => rsync
tried again. The C<fetch> method will only fail when all options are
exhausted, and it was not able to retrieve the file.
+C<iosock> is a very limited L<IO::Socket::INET> based mechanism for
+retrieving C<http> schemed urls. It doesn't follow redirects for instance.
+
A special note about fetching files from an ftp uri:
By default, all ftp connections are done in passive mode. To change
curl => curl
rsync => rsync
lftp => lftp
+ IO::Socket => iosock
=head1 FREQUENTLY ASKED QUESTIONS