📄 file::fetch.3
字号:
The name of the output file. This is the same as \f(CW$ff\fR\->file,but any query parameters are stripped off. For example:.Sp.Vb 1\& http://example.com/index.html?x=y.Ve.Spwould make the output file be \f(CW\*(C`index.html\*(C'\fR rather than \&\f(CW\*(C`index.html?x=y\*(C'\fR..SH "METHODS".IX Header "METHODS".ie n .Sh "$ff = File::Fetch\->new( uri => 'http://some.where.com/dir/file.txt' );".el .Sh "\f(CW$ff\fP = File::Fetch\->new( uri => 'http://some.where.com/dir/file.txt' );".IX Subsection "$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 \f(CW\*(C`fetch\*(C'\fRed and returns it..PPReturns false on failure..ie n .Sh "$ff\->fetch( [to => /my/output/dir/] )".el .Sh "\f(CW$ff\fP\->fetch( [to => /my/output/dir/] )".IX Subsection "$ff->fetch( [to => /my/output/dir/] )"Fetches the file you requested. By default it writes to \f(CW\*(C`cwd()\*(C'\fR,but you can override that by specifying the \f(CW\*(C`to\*(C'\fR argument..PPReturns the full path to the downloaded file on success, and falseon failure..ie n .Sh "$ff\->error([\s-1BOOL\s0])".el .Sh "\f(CW$ff\fP\->error([\s-1BOOL\s0])".IX Subsection "$ff->error([BOOL])"Returns the last encountered error as string.Pass it a true value to get the \f(CW\*(C`Carp::longmess()\*(C'\fR output instead..SH "HOW IT WORKS".IX Header "HOW IT WORKS"File::Fetch is able to fetch a variety of uris, by using severalexternal programs and modules..PPBelow is a mapping of what utilities will be used in what orderfor what schemes, if available:.PP.Vb 4\& file => LWP, file\& http => LWP, wget, curl, lynx\& ftp => LWP, Net::FTP, wget, curl, ncftp, ftp\& rsync => rsync.Ve.PPIf you'd like to disable the use of one or more of these utilitiesand/or modules, see the \f(CW$BLACKLIST\fR variable further down..PPIf a utility or module isn't available, it will be marked in a cache(see the \f(CW$METHOD_FAIL\fR variable further down), so it will not betried again. The \f(CW\*(C`fetch\*(C'\fR method will only fail when all options areexhausted, and it was not able to retrieve the file..PPA special note about fetching files from an ftp uri:.PPBy default, all ftp connections are done in passive mode. To changethat, see the \f(CW$FTP_PASSIVE\fR variable further down..PPFurthermore, ftp uris only support anonymous connections, so nonamed user/password pair can be passed along..PP\&\f(CW\*(C`/bin/ftp\*(C'\fR is blacklisted by default; see the \f(CW$BLACKLIST\fR variablefurther down..SH "GLOBAL VARIABLES".IX Header "GLOBAL VARIABLES"The behaviour of File::Fetch can be altered by changing the followingglobal variables:.ie n .Sh "$File::Fetch::FROM_EMAIL".el .Sh "\f(CW$File::Fetch::FROM_EMAIL\fP".IX Subsection "$File::Fetch::FROM_EMAIL"This is the email address that will be sent as your anonymous ftppassword..PPDefault is \f(CW\*(C`File\-Fetch@example.com\*(C'\fR..ie n .Sh "$File::Fetch::USER_AGENT".el .Sh "\f(CW$File::Fetch::USER_AGENT\fP".IX Subsection "$File::Fetch::USER_AGENT"This is the useragent as \f(CW\*(C`LWP\*(C'\fR will report it..PPDefault is \f(CW\*(C`File::Fetch/$VERSION\*(C'\fR..ie n .Sh "$File::Fetch::FTP_PASSIVE".el .Sh "\f(CW$File::Fetch::FTP_PASSIVE\fP".IX Subsection "$File::Fetch::FTP_PASSIVE"This variable controls whether the environment variable \f(CW\*(C`FTP_PASSIVE\*(C'\fRand any passive switches to commandline tools will be set to true..PPDefault value is 1..PPNote: When \f(CW$FTP_PASSIVE\fR is true, \f(CW\*(C`ncftp\*(C'\fR will not be used to fetchfiles, since passive mode can only be set interactively for this binary.ie n .Sh "$File::Fetch::TIMEOUT".el .Sh "\f(CW$File::Fetch::TIMEOUT\fP".IX Subsection "$File::Fetch::TIMEOUT"When set, controls the network timeout (counted in seconds)..PPDefault value is 0..ie n .Sh "$File::Fetch::WARN".el .Sh "\f(CW$File::Fetch::WARN\fP".IX Subsection "$File::Fetch::WARN"This variable controls whether errors encountered internally by\&\f(CW\*(C`File::Fetch\*(C'\fR should be \f(CW\*(C`carp\*(C'\fR'd or not..PPSet to false to silence warnings. Inspect the output of the \f(CW\*(C`error()\*(C'\fRmethod manually to see what went wrong..PPDefaults to \f(CW\*(C`true\*(C'\fR..ie n .Sh "$File::Fetch::DEBUG".el .Sh "\f(CW$File::Fetch::DEBUG\fP".IX Subsection "$File::Fetch::DEBUG"This enables debugging output when calling commandline utilities tofetch files.This also enables \f(CW\*(C`Carp::longmess\*(C'\fR errors, instead of the regular\&\f(CW\*(C`carp\*(C'\fR errors..PPGood for tracking down why things don't work with your particularsetup..PPDefault is 0..ie n .Sh "$File::Fetch::BLACKLIST".el .Sh "\f(CW$File::Fetch::BLACKLIST\fP".IX Subsection "$File::Fetch::BLACKLIST"This is an array ref holding blacklisted modules/utilities for fetchingfiles with..PPTo disallow the use of, for example, \f(CW\*(C`LWP\*(C'\fR and \f(CW\*(C`Net::FTP\*(C'\fR, you couldset \f(CW$File::Fetch::BLACKLIST\fR to:.PP.Vb 1\& $File::Fetch::BLACKLIST = [qw|lwp netftp|].Ve.PPThe default blacklist is [qw|ftp|], as \f(CW\*(C`/bin/ftp\*(C'\fR is rather unreliable..PPSee the note on \f(CW\*(C`MAPPING\*(C'\fR below..ie n .Sh "$File::Fetch::METHOD_FAIL".el .Sh "\f(CW$File::Fetch::METHOD_FAIL\fP".IX Subsection "$File::Fetch::METHOD_FAIL"This is a hashref registering what modules/utilities were known to failfor fetching files (mostly because they weren't installed)..PPYou can reset this cache by assigning an empty hashref to it, orindividually remove keys..PPSee the note on \f(CW\*(C`MAPPING\*(C'\fR below..SH "MAPPING".IX Header "MAPPING"Here's a quick mapping for the utilities/modules, and their names forthe \f(CW$BLACKLIST\fR, \f(CW$METHOD_FAIL\fR and other internal functions..PP.Vb 8\& LWP => lwp\& Net::FTP => netftp\& wget => wget\& lynx => lynx\& ncftp => ncftp\& ftp => ftp\& curl => curl\& rsync => rsync.Ve.SH "FREQUENTLY ASKED QUESTIONS".IX Header "FREQUENTLY ASKED QUESTIONS".Sh "So how do I use a proxy with File::Fetch?".IX Subsection "So how do I use a proxy with File::Fetch?"\&\f(CW\*(C`File::Fetch\*(C'\fR currently only supports proxies with LWP::UserAgent.You will need to set your environment variables accordingly. Forexample, to use an ftp proxy:.PP.Vb 1\& $ENV{ftp_proxy} = \*(Aqfoo.com\*(Aq;.Ve.PPRefer to the LWP::UserAgent manpage for more details..Sh "I used 'lynx' to fetch a file, but its contents is all wrong!".IX Subsection "I used 'lynx' to fetch a file, but its contents is all wrong!"\&\f(CW\*(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 \f(CW\*(C`404 handler\*(C'\fR), you will get that contents instead..PPSadly, \f(CW\*(C`lynx\*(C'\fR doesn't support any options to return a different exitcode on non\-\f(CW\*(C`200 OK\*(C'\fR status, giving us no way to tell the differencebetween a 'successfull' fetch and a custom error page..PPTherefor, we recommend to only use \f(CW\*(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..Sh "Files I'm trying to fetch have reserved characters or non-ASCII characters in them. What do I do?".IX Subsection "Files I'm trying to fetch have reserved characters or non-ASCII characters in them. What do I do?"\&\f(CW\*(C`File::Fetch\*(C'\fR is relatively smart about things. When trying to write a file to disk, it removes the \f(CW\*(C`query parameters\*(C'\fR (see the \&\f(CW\*(C`output_file\*(C'\fR method for details) from the file name before creatingit. In most cases this suffices..PPIf you have any other characters you need to escape, please install the \f(CW\*(C`URI::Escape\*(C'\fR module from \s-1CPAN\s0, and pre-encode your \s-1URI\s0 beforepassing it to \f(CW\*(C`File::Fetch\*(C'\fR. You can read about the details of URIs and \s-1URI\s0 encoding here:.PP.Vb 1\& http://www.faqs.org/rfcs/rfc2396.html.Ve.SH "TODO".IX Header "TODO".ie n .IP "Implement $PREFER_BIN" 4.el .IP "Implement \f(CW$PREFER_BIN\fR" 4.IX Item "Implement $PREFER_BIN"To indicate to rather use commandline tools than modules.SH "BUG REPORTS".IX Header "BUG REPORTS"Please report bugs or other issues to <bug\-file\-fetch@rt.cpan.org<gt>..SH "AUTHOR".IX Header "AUTHOR"This module by Jos Boumans <kane@cpan.org>..SH "COPYRIGHT".IX Header "COPYRIGHT"This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -