™.. File::Fetch - Online Linux Manual PageSection : 3pm
Updated : 2017-03-22
Source : perl v5.10.1
Note : Perl Programmers Reference Guide
NAMEFile::Fetch − A generic file fetching mechanism
SYNOPSIS use File::Fetch;
### build a File::Fetch object ###
my $ff = File::Fetch−>new(uri => 'http://some.where.com/dir/a.txt');
### fetch the uri to cwd() ###
my $where = $ff−>fetch() or die $ff−>error;
### fetch the uri to /tmp ###
my $where = $ff−>fetch( to => '/tmp' );
### parsed bits from the uri ###
$ff−>uri;
$ff−>scheme;
$ff−>host;
$ff−>path;
$ff−>file;
DESCRIPTIONFile::Fetch is a generic file fetching mechanism. It allows you to fetch any file pointed to by a \*(C`ftp\*(C'\fR, \f(CW\*(C`http\*(C'\fR, \*(C`file\*(C'\fR, or \f(CW\*(C`rsync\*(C'\fR uri by a number of different means. See the \*(C`HOW IT WORKS\*(C'\fR section further down for details.
ACCESSORSA \*(C`File::Fetch\*(C'\fR object has the following accessors $ff−>uri The uri you passed to the constructor $ff−>scheme The scheme from the uri (like 'file', 'http', etc) $ff−>host The hostname in the uri. Will be empty if host was originally 'localhost' for a 'file://' url. $ff−>vol On operating systems with the concept of a volume the second element of a file:// is considered to the be volume specification for the file. Thus on Win32 this routine returns the volume, on other operating systems this returns nothing. On Windows this value may be empty if the uri is to a network share, in which case the 'share' property will be defined. Additionally, volume specifications that use '|' as ':' will be converted on read to use ':'. On VMS, which has a volume concept, this field will be empty because VMS file specifications are converted to absolute UNIX format and the volume information is transparently included. $ff−>share On systems with the concept of a network share (currently only Windows) returns the sharename from a file://// url. On other operating systems returns empty. $ff−>path The path from the uri, will be at least a single '/'. $ff−>file The name of the remote file. For the local file name, the result of $ff−>output_file will be used. $ff−>output_file The name of the output file. This is the same as $ff−>file, but any query parameters are stripped off. For example: http://example.com/index.html?x=y
would make the output file be \*(C`index.html\*(C'\fR rather than \*(C`index.html?x=y\*(C'\fR.
METHODS
$ff = File::Fetch−>new( uri => 'http://some.where.com/dir/file.txt' );Parses the uri and creates a corresponding File::Fetch::Item object, that is ready to be \*(C`fetch\*(C'\fRed and returns it. Returns false on failure.
$where = $ff−>fetch( [to => /my/output/dir/ | \$scalar] )Fetches the file you requested and returns the full path to the file. By default it writes to \*(C`cwd()\*(C'\fR, but you can override that by specifying the \*(C`to\*(C'\fR argument: ### file fetch to /tmp, full path to the file in $where
$where = $ff−>fetch( to => '/tmp' );
### file slurped into $scalar, full path to the file in $where
### file is downloaded to a temp directory and cleaned up at exit time
$where = $ff−>fetch( to => \$scalar );
Returns the full path to the downloaded file on success, and false on failure.
$ff−>error([BOOL])Returns the last encountered error as string. Pass it a true value to get the \*(C`Carp::longmess()\*(C'\fR output instead.
HOW IT WORKSFile::Fetch is able to fetch a variety of uris, by using several external programs and modules. Below is a mapping of what utilities will be used in what order for what schemes, if available: file => LWP, lftp, file
http => LWP, wget, curl, lftp, lynx, iosock
ftp => LWP, Net::FTP, wget, curl, lftp, ncftp, ftp
rsync => rsync
If you'd like to disable the use of one or more of these utilities and/or modules, see the $BLACKLIST variable further down. If a utility or module isn't available, it will be marked in a cache (see the $METHOD_FAIL variable further down), so it will not be tried again. The \*(C`fetch\*(C'\fR method will only fail when all options are exhausted, and it was not able to retrieve the file. \*(C`iosock\*(C'\fR is a very limited IO::Socket::INET based mechanism for retrieving \*(C`http\*(C'\fR 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 that, see the $FTP_PASSIVE variable further down. Furthermore, ftp uris only support anonymous connections, so no named user/password pair can be passed along. \*(C`/bin/ftp\*(C'\fR is blacklisted by default; see the \f(CW$BLACKLIST\fR variable further down.
GLOBAL VARIABLESThe behaviour of File::Fetch can be altered by changing the following global variables:
$File::Fetch::FROM_EMAILThis is the email address that will be sent as your anonymous ftp password. Default is \*(C`File\-Fetch@example.com\*(C'\fR.
$File::Fetch::USER_AGENTThis is the useragent as \*(C`LWP\*(C'\fR will report it. Default is \*(C`File::Fetch/$VERSION\*(C'\fR.
$File::Fetch::FTP_PASSIVEThis variable controls whether the environment variable \*(C`FTP_PASSIVE\*(C'\fR and any passive switches to commandline tools will be set to true. Default value is 1. Note: When $FTP_PASSIVE is true, \*(C`ncftp\*(C'\fR will not be used to fetch files, since passive mode can only be set interactively for this binary
$File::Fetch::TIMEOUTWhen set, controls the network timeout (counted in seconds). Default value is 0.
$File::Fetch::WARNThis variable controls whether errors encountered internally by \*(C`File::Fetch\*(C'\fR should be \f(CW\*(C`carp\*(C'\fR'd or not. Set to false to silence warnings. Inspect the output of the \*(C`error()\*(C'\fR method manually to see what went wrong. Defaults to \*(C`true\*(C'\fR.
$File::Fetch::DEBUGThis enables debugging output when calling commandline utilities to fetch files. This also enables \*(C`Carp::longmess\*(C'\fR errors, instead of the regular \*(C`carp\*(C'\fR errors. Good for tracking down why things don't work with your particular setup. Default is 0.
$File::Fetch::BLACKLISTThis is an array ref holding blacklisted modules/utilities for fetching files with. To disallow the use of, for example, \*(C`LWP\*(C'\fR and \f(CW\*(C`Net::FTP\*(C'\fR, you could set $File::Fetch::BLACKLIST to: $File::Fetch::BLACKLIST = [qw|lwp netftp|]
The default blacklist is [qw|ftp|], as \*(C`/bin/ftp\*(C'\fR is rather unreliable. See the note on \*(C`MAPPING\*(C'\fR below.
$File::Fetch::METHOD_FAILThis is a hashref registering what modules/utilities were known to fail for fetching files (mostly because they weren't installed). You can reset this cache by assigning an empty hashref to it, or individually remove keys. See the note on \*(C`MAPPING\*(C'\fR below.
MAPPINGHere's a quick mapping for the utilities/modules, and their names for the $BLACKLIST, $METHOD_FAIL and other internal functions. LWP => lwp
Net::FTP => netftp
wget => wget
lynx => lynx
ncftp => ncftp
ftp => ftp
curl => curl
rsync => rsync
lftp => lftp
IO::Socket => iosock
FREQUENTLY ASKED QUESTIONS
So how do I use a proxy with File::Fetch?\*(C`File::Fetch\*(C'\fR currently only supports proxies with LWP::UserAgent. You will need to set your environment variables accordingly. For example, to use an ftp proxy: $ENV{ftp_proxy} = 'foo.com';
Refer to the LWP::UserAgent manpage for more details.
I used 'lynx' to fetch a file, but its contents is all wrong!\*(C`lynx\*(C'\fR can only fetch remote files by dumping its contents to \f(CW\*(C`STDOUT\*(C'\fR, which we in turn capture. If that content is a 'custom' error file (like, say, a \*(C`404 handler\*(C'\fR), you will get that contents instead. Sadly, \*(C`lynx\*(C'\fR doesn't support any options to return a different exit code on non−\*(C`200 OK\*(C'\fR status, giving us no way to tell the difference between a 'successfull' fetch and a custom error page. Therefor, we recommend to only use \*(C`lynx\*(C'\fR as a last resort. This is why it is at the back of our list of methods to try as well.
Files I'm trying to fetch have reserved characters or non-ASCII characters in them. What do I do?\*(C`File::Fetch\*(C'\fR is relatively smart about things. When trying to write a file to disk, it removes the \*(C`query parameters\*(C'\fR (see the \*(C`output_file\*(C'\fR method for details) from the file name before creating it. In most cases this suffices. If you have any other characters you need to escape, please install the \*(C`URI::Escape\*(C'\fR module from \s-1CPAN\s0, and pre-encode your \s-1URI\s0 before passing it to \*(C`File::Fetch\*(C'\fR. You can read about the details of URIs and URI encoding here: http://www.faqs.org/rfcs/rfc2396.html
TODOImplement $PREFER_BIN To indicate to rather use commandline tools than modules
BUG REPORTSPlease report bugs or other issues to <bug−file−fetch@rt.cpan.org<gt>.
AUTHORThis module by Jos Boumans <kane@cpan.org>.
COPYRIGHTThis library is free software; you may redistribute and/or modify it under the same terms as Perl itself. 0
Johanes Gumabo
Data Size : 35,733 byte
man-File::Fetch.3pmBuild : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 6 / 168,832
Visitor ID : :
Visitor IP : 3.145.2.6 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.
ERROR : Need New Coding : (parse_manual_page_|249|File::Fetch.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\|
) (htmlprn|149|File::Fetch.3pm|36/37|.el══─{─══. ds -- — |.el══─{─══. ds -- \|\(em\|
) (parse_manual_page_|249|File::Fetch.3pm|41|br══─}─══|'br══─}─══
) (htmlprn|149|File::Fetch.3pm|41|'br══─}─══ |'br══─}─══
) (rof_nr_x|149|File::Fetch.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (rof_unit_scale_px|41|File::Fetch.3pm|51/52|F|.ie \nF ══─{─══. de IX
) (rof_if|19|File::Fetch.3pm|51/52|\nF|.ie \nF ══─{─══. de IX
) (htmlprn|149|File::Fetch.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX
) (rof_escape_sequence|91|File::Fetch.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2"
) (parse_manual_page_|249|File::Fetch.3pm|57|══─}─══|.══─}─══
) (htmlprn|149|File::Fetch.3pm|57|.══─}─══ |.══─}─══
) (rof_escape_sequence|91|File::Fetch.3pm|159|\*(C`ftp\*(C'\fR, \f(CW\*(C`http\*(C'\fR, |It allows you to fetch any file pointed to by a \f(CW\*(C`ftp\*(C'\fR, \f(CW\*(C`http\*(C'\fR,
) (rof_escape_sequence|91|File::Fetch.3pm|160|\*(C`file\*(C'\fR, or \f(CW\*(C`rsync\*(C'\fR uri by a number of different means. |\&\f(CW\*(C`file\*(C'\fR, or \f(CW\*(C`rsync\*(C'\fR uri by a number of different means.
) (rof_escape_sequence|91|File::Fetch.3pm|162|\*(C`HOW IT WORKS\*(C'\fR section further down for details. |See the \f(CW\*(C`HOW IT WORKS\*(C'\fR section further down for details.
) (rof_escape_sequence|91|File::Fetch.3pm|165|\*(C`File::Fetch\*(C'\fR object has the following accessors |A \f(CW\*(C`File::Fetch\*(C'\fR object has the following accessors
) (rof_escape_sequence|91|File::Fetch.3pm|218|\*(C`index.html\*(C'\fR rather than |would make the output file be \f(CW\*(C`index.html\*(C'\fR rather than
) (rof_escape_sequence|91|File::Fetch.3pm|219|\*(C`index.html?x=y\*(C'\fR. |\&\f(CW\*(C`index.html?x=y\*(C'\fR.
) (rof_escape_sequence|91|File::Fetch.3pm|226|\*(C`fetch\*(C'\fRed and returns it. |that is ready to be \f(CW\*(C`fetch\*(C'\fRed and returns it.
) (rof_escape_sequence|91|File::Fetch.3pm|234|\*(C`cwd()\*(C'\fR, but you can override that by specifying |By default it writes to \f(CW\*(C`cwd()\*(C'\fR, but you can override that by specifying
) (rof_escape_sequence|91|File::Fetch.3pm|235|\*(C`to\*(C'\fR argument: |the \f(CW\*(C`to\*(C'\fR argument:
) (rof_escape_sequence|91|File::Fetch.3pm|252|\*(C`Carp::longmess()\*(C'\fR output instead. |Pass it a true value to get the \f(CW\*(C`Carp::longmess()\*(C'\fR output instead.
) (rof_escape_sequence|91|File::Fetch.3pm|273|\*(C`fetch\*(C'\fR method will only fail when all options are |tried again. The \f(CW\*(C`fetch\*(C'\fR method will only fail when all options are
) (rof_escape_sequence|91|File::Fetch.3pm|276|\*(C`iosock\*(C'\fR is a very limited IO::Socket::INET based mechanism for |\&\f(CW\*(C`iosock\*(C'\fR is a very limited IO::Socket::INET based mechanism for
) (rof_escape_sequence|91|File::Fetch.3pm|277|\*(C`http\*(C'\fR schemed urls. It doesn't follow redirects for instance. |retrieving \f(CW\*(C`http\*(C'\fR schemed urls. It doesn't follow redirects for instance.
) (rof_escape_sequence|91|File::Fetch.3pm|287|\*(C`/bin/ftp\*(C'\fR is blacklisted by default; see the \f(CW$BLACKLIST\fR variable |\&\f(CW\*(C`/bin/ftp\*(C'\fR is blacklisted by default; see the \f(CW$BLACKLIST\fR variable
) (rof_escape_sequence|91|File::Fetch.3pm|299|\*(C`File\-Fetch@example.com\*(C'\fR. |Default is \f(CW\*(C`File\-Fetch@example.com\*(C'\fR.
) (rof_escape_sequence|91|File::Fetch.3pm|303|\*(C`LWP\*(C'\fR will report it. |This is the useragent as \f(CW\*(C`LWP\*(C'\fR will report it.
) (rof_escape_sequence|91|File::Fetch.3pm|305|\*(C`File::Fetch/$VERSION\*(C'\fR. |Default is \f(CW\*(C`File::Fetch/$VERSION\*(C'\fR.
) (rof_escape_sequence|91|File::Fetch.3pm|309|\*(C`FTP_PASSIVE\*(C'\fR |This variable controls whether the environment variable \f(CW\*(C`FTP_PASSIVE\*(C'\fR
) (rof_escape_sequence|91|File::Fetch.3pm|314|\*(C`ncftp\*(C'\fR will not be used to fetch |Note: When \f(CW$FTP_PASSIVE\fR is true, \f(CW\*(C`ncftp\*(C'\fR will not be used to fetch
) (rof_escape_sequence|91|File::Fetch.3pm|326|\*(C`File::Fetch\*(C'\fR should be \f(CW\*(C`carp\*(C'\fR'd or not. |\&\f(CW\*(C`File::Fetch\*(C'\fR should be \f(CW\*(C`carp\*(C'\fR'd or not.
) (rof_escape_sequence|91|File::Fetch.3pm|328|\*(C`error()\*(C'\fR |Set to false to silence warnings. Inspect the output of the \f(CW\*(C`error()\*(C'\fR
) (rof_escape_sequence|91|File::Fetch.3pm|331|\*(C`true\*(C'\fR. |Defaults to \f(CW\*(C`true\*(C'\fR.
) (rof_escape_sequence|91|File::Fetch.3pm|337|\*(C`Carp::longmess\*(C'\fR errors, instead of the regular |This also enables \f(CW\*(C`Carp::longmess\*(C'\fR errors, instead of the regular
) (rof_escape_sequence|91|File::Fetch.3pm|338|\*(C`carp\*(C'\fR errors. |\&\f(CW\*(C`carp\*(C'\fR errors.
) (rof_escape_sequence|91|File::Fetch.3pm|350|\*(C`LWP\*(C'\fR and \f(CW\*(C`Net::FTP\*(C'\fR, you could |To disallow the use of, for example, \f(CW\*(C`LWP\*(C'\fR and \f(CW\*(C`Net::FTP\*(C'\fR, you could
) (rof_escape_sequence|91|File::Fetch.3pm|357|\*(C`/bin/ftp\*(C'\fR is rather unreliable. |The default blacklist is [qw|ftp|], as \f(CW\*(C`/bin/ftp\*(C'\fR is rather unreliable.
) (rof_escape_sequence|91|File::Fetch.3pm|359|\*(C`MAPPING\*(C'\fR below. |See the note on \f(CW\*(C`MAPPING\*(C'\fR below.
) (rof_escape_sequence|91|File::Fetch.3pm|369|\*(C`MAPPING\*(C'\fR below. |See the note on \f(CW\*(C`MAPPING\*(C'\fR below.
) (rof_escape_sequence|91|File::Fetch.3pm|391|\*(C`File::Fetch\*(C'\fR currently only supports proxies with LWP::UserAgent. |\&\f(CW\*(C`File::Fetch\*(C'\fR currently only supports proxies with LWP::UserAgent.
) (rof_escape_sequence|91|File::Fetch.3pm|402|\*(C`lynx\*(C'\fR can only fetch remote files by dumping its contents to \f(CW\*(C`STDOUT\*(C'\fR, |\&\f(CW\*(C`lynx\*(C'\fR can only fetch remote files by dumping its contents to \f(CW\*(C`STDOUT\*(C'\fR,
) (rof_escape_sequence|91|File::Fetch.3pm|404|\*(C`404 handler\*(C'\fR), you will get that contents instead. |(like, say, a \f(CW\*(C`404 handler\*(C'\fR), you will get that contents instead.
) (rof_escape_sequence|91|File::Fetch.3pm|406|\*(C`lynx\*(C'\fR doesn't support any options to return a different exit |Sadly, \f(CW\*(C`lynx\*(C'\fR doesn't support any options to return a different exit
) (rof_escape_sequence|91|File::Fetch.3pm|407|\*(C`200 OK\*(C'\fR status, giving us no way to tell the difference |code on non\-\f(CW\*(C`200 OK\*(C'\fR status, giving us no way to tell the difference
) (rof_escape_sequence|91|File::Fetch.3pm|410|\*(C`lynx\*(C'\fR as a last resort. This is |Therefor, we recommend to only use \f(CW\*(C`lynx\*(C'\fR as a last resort. This is
) (rof_escape_sequence|91|File::Fetch.3pm|414|\*(C`File::Fetch\*(C'\fR is relatively smart about things. When trying to write |\&\f(CW\*(C`File::Fetch\*(C'\fR is relatively smart about things. When trying to write
) (rof_escape_sequence|91|File::Fetch.3pm|415|\*(C`query parameters\*(C'\fR (see the |a file to disk, it removes the \f(CW\*(C`query parameters\*(C'\fR (see the
) (rof_escape_sequence|91|File::Fetch.3pm|416|\*(C`output_file\*(C'\fR method for details) from the file name before creating |\&\f(CW\*(C`output_file\*(C'\fR method for details) from the file name before creating
) (rof_escape_sequence|91|File::Fetch.3pm|420|\*(C`URI::Escape\*(C'\fR module from \s-1CPAN\s0, and pre-encode your \s-1URI\s0 before |the \f(CW\*(C`URI::Escape\*(C'\fR module from \s-1CPAN\s0, and pre-encode your \s-1URI\s0 before
) (rof_escape_sequence|91|File::Fetch.3pm|421|\*(C`File::Fetch\*(C'\fR. You can read about the details of URIs |passing it to \f(CW\*(C`File::Fetch\*(C'\fR. You can read about the details of URIs
)