CINXE.COM
File::Fetch - A generic file fetching mechanism - Perldoc Browser
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>File::Fetch - A generic file fetching mechanism - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/File::Fetch"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.20.0</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/File::Fetch">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/File::Fetch">5.40.1</a> <a class="dropdown-item" href="/5.40.0/File::Fetch">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/File::Fetch">5.38.3</a> <a class="dropdown-item" href="/5.38.2/File::Fetch">5.38.2</a> <a class="dropdown-item" href="/5.38.1/File::Fetch">5.38.1</a> <a class="dropdown-item" href="/5.38.0/File::Fetch">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/File::Fetch">5.36.3</a> <a class="dropdown-item" href="/5.36.2/File::Fetch">5.36.2</a> <a class="dropdown-item" href="/5.36.1/File::Fetch">5.36.1</a> <a class="dropdown-item" href="/5.36.0/File::Fetch">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/File::Fetch">5.34.3</a> <a class="dropdown-item" href="/5.34.2/File::Fetch">5.34.2</a> <a class="dropdown-item" href="/5.34.1/File::Fetch">5.34.1</a> <a class="dropdown-item" href="/5.34.0/File::Fetch">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/File::Fetch">5.32.1</a> <a class="dropdown-item" href="/5.32.0/File::Fetch">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/File::Fetch">5.30.3</a> <a class="dropdown-item" href="/5.30.2/File::Fetch">5.30.2</a> <a class="dropdown-item" href="/5.30.1/File::Fetch">5.30.1</a> <a class="dropdown-item" href="/5.30.0/File::Fetch">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/File::Fetch">5.28.3</a> <a class="dropdown-item" href="/5.28.2/File::Fetch">5.28.2</a> <a class="dropdown-item" href="/5.28.1/File::Fetch">5.28.1</a> <a class="dropdown-item" href="/5.28.0/File::Fetch">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/File::Fetch">5.26.3</a> <a class="dropdown-item" href="/5.26.2/File::Fetch">5.26.2</a> <a class="dropdown-item" href="/5.26.1/File::Fetch">5.26.1</a> <a class="dropdown-item" href="/5.26.0/File::Fetch">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/File::Fetch">5.24.4</a> <a class="dropdown-item" href="/5.24.3/File::Fetch">5.24.3</a> <a class="dropdown-item" href="/5.24.2/File::Fetch">5.24.2</a> <a class="dropdown-item" href="/5.24.1/File::Fetch">5.24.1</a> <a class="dropdown-item" href="/5.24.0/File::Fetch">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/File::Fetch">5.22.4</a> <a class="dropdown-item" href="/5.22.3/File::Fetch">5.22.3</a> <a class="dropdown-item" href="/5.22.2/File::Fetch">5.22.2</a> <a class="dropdown-item" href="/5.22.1/File::Fetch">5.22.1</a> <a class="dropdown-item" href="/5.22.0/File::Fetch">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/File::Fetch">5.20.3</a> <a class="dropdown-item" href="/5.20.2/File::Fetch">5.20.2</a> <a class="dropdown-item" href="/5.20.1/File::Fetch">5.20.1</a> <a class="dropdown-item active" href="/5.20.0/File::Fetch">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/File::Fetch">5.18.4</a> <a class="dropdown-item" href="/5.18.3/File::Fetch">5.18.3</a> <a class="dropdown-item" href="/5.18.2/File::Fetch">5.18.2</a> <a class="dropdown-item" href="/5.18.1/File::Fetch">5.18.1</a> <a class="dropdown-item" href="/5.18.0/File::Fetch">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/File::Fetch">5.16.3</a> <a class="dropdown-item" href="/5.16.2/File::Fetch">5.16.2</a> <a class="dropdown-item" href="/5.16.1/File::Fetch">5.16.1</a> <a class="dropdown-item" href="/5.16.0/File::Fetch">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/File::Fetch">5.14.4</a> <a class="dropdown-item" href="/5.14.3/File::Fetch">5.14.3</a> <a class="dropdown-item" href="/5.14.2/File::Fetch">5.14.2</a> <a class="dropdown-item" href="/5.14.1/File::Fetch">5.14.1</a> <a class="dropdown-item" href="/5.14.0/File::Fetch">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/File::Fetch">5.12.5</a> <a class="dropdown-item" href="/5.12.4/File::Fetch">5.12.4</a> <a class="dropdown-item" href="/5.12.3/File::Fetch">5.12.3</a> <a class="dropdown-item" href="/5.12.2/File::Fetch">5.12.2</a> <a class="dropdown-item" href="/5.12.1/File::Fetch">5.12.1</a> <a class="dropdown-item" href="/5.12.0/File::Fetch">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/File::Fetch">5.10.1</a> <a class="dropdown-item" href="/5.10.0/File::Fetch">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/File::Fetch">5.8.9</a> <a class="dropdown-item" href="/5.8.8/File::Fetch">5.8.8</a> <a class="dropdown-item" href="/5.8.7/File::Fetch">5.8.7</a> <a class="dropdown-item" href="/5.8.6/File::Fetch">5.8.6</a> <a class="dropdown-item" href="/5.8.5/File::Fetch">5.8.5</a> <a class="dropdown-item" href="/5.8.4/File::Fetch">5.8.4</a> <a class="dropdown-item" href="/5.8.3/File::Fetch">5.8.3</a> <a class="dropdown-item" href="/5.8.2/File::Fetch">5.8.2</a> <a class="dropdown-item" href="/5.8.1/File::Fetch">5.8.1</a> <a class="dropdown-item" href="/5.8.0/File::Fetch">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/File::Fetch">5.6.2</a> <a class="dropdown-item" href="/5.6.1/File::Fetch">5.6.1</a> <a class="dropdown-item" href="/5.6.0/File::Fetch">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/File::Fetch">5.005_04</a> <a class="dropdown-item" href="/5.005_03/File::Fetch">5.005_03</a> <a class="dropdown-item" href="/5.005_02/File::Fetch">5.005_02</a> <a class="dropdown-item" href="/5.005_01/File::Fetch">5.005_01</a> <a class="dropdown-item" href="/5.005/File::Fetch">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/File::Fetch">blead</a> <a class="dropdown-item" href="/5.41.10/File::Fetch">5.41.10</a> <a class="dropdown-item" href="/5.41.9/File::Fetch">5.41.9</a> <a class="dropdown-item" href="/5.41.8/File::Fetch">5.41.8</a> <a class="dropdown-item" href="/5.41.7/File::Fetch">5.41.7</a> <a class="dropdown-item" href="/5.41.6/File::Fetch">5.41.6</a> <a class="dropdown-item" href="/5.41.5/File::Fetch">5.41.5</a> <a class="dropdown-item" href="/5.41.4/File::Fetch">5.41.4</a> <a class="dropdown-item" href="/5.41.3/File::Fetch">5.41.3</a> <a class="dropdown-item" href="/5.41.2/File::Fetch">5.41.2</a> <a class="dropdown-item" href="/5.41.1/File::Fetch">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/File::Fetch">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/File::Fetch">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/File::Fetch">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/File::Fetch">5.39.10</a> <a class="dropdown-item" href="/5.39.9/File::Fetch">5.39.9</a> <a class="dropdown-item" href="/5.39.8/File::Fetch">5.39.8</a> <a class="dropdown-item" href="/5.39.7/File::Fetch">5.39.7</a> <a class="dropdown-item" href="/5.39.6/File::Fetch">5.39.6</a> <a class="dropdown-item" href="/5.39.5/File::Fetch">5.39.5</a> <a class="dropdown-item" href="/5.39.4/File::Fetch">5.39.4</a> <a class="dropdown-item" href="/5.39.3/File::Fetch">5.39.3</a> <a class="dropdown-item" href="/5.39.2/File::Fetch">5.39.2</a> <a class="dropdown-item" href="/5.39.1/File::Fetch">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/File::Fetch">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.20.0/perl">Perl</a> <a class="dropdown-item" href="/5.20.0/perlintro">Intro</a> <a class="dropdown-item" href="/5.20.0/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.20.0/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.20.0/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.0/perlop">Operators</a> <a class="dropdown-item" href="/5.20.0/functions">Functions</a> <a class="dropdown-item" href="/5.20.0/variables">Variables</a> <a class="dropdown-item" href="/5.20.0/modules">Modules</a> <a class="dropdown-item" href="/5.20.0/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.0/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.20.0/perlcommunity">Community</a> <a class="dropdown-item" href="/5.20.0/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.20.0/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.20.0/File::Fetch">File::Fetch</a> <div id="more"> (<a href="/5.20.0/File::Fetch.txt">source</a>, <a href="https://metacpan.org/pod/File::Fetch">CPAN</a>) </div> <div id="moduleversion">version 0.48</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.20.0. <a href="/File::Fetch">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> </li> <li> <a class="text-decoration-none" href="#ACCESSORS">ACCESSORS</a> </li> <li> <a class="text-decoration-none" href="#METHODS">METHODS</a> <ul> <li> <a class="text-decoration-none" href="#$ff-=-File::Fetch-%3Enew(-uri-=%3E-'http://some.where.com/dir/file.txt'-);">$ff = File::Fetch->new( uri => 'http://some.where.com/dir/file.txt' );</a> </li> <li> <a class="text-decoration-none" href="#$where-=-$ff-%3Efetch(-%5Bto-=%3E-/my/output/dir/-%7C-%5C$scalar%5D-)">$where = $ff->fetch( [to => /my/output/dir/ | \$scalar] )</a> </li> <li> <a class="text-decoration-none" href="#$ff-%3Eerror(%5BBOOL%5D)">$ff->error([BOOL])</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#HOW-IT-WORKS">HOW IT WORKS</a> </li> <li> <a class="text-decoration-none" href="#GLOBAL-VARIABLES">GLOBAL VARIABLES</a> <ul> <li> <a class="text-decoration-none" href="#$File::Fetch::FROM_EMAIL">$File::Fetch::FROM_EMAIL</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::USER_AGENT">$File::Fetch::USER_AGENT</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::FTP_PASSIVE">$File::Fetch::FTP_PASSIVE</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::TIMEOUT">$File::Fetch::TIMEOUT</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::WARN">$File::Fetch::WARN</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::DEBUG">$File::Fetch::DEBUG</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::BLACKLIST">$File::Fetch::BLACKLIST</a> </li> <li> <a class="text-decoration-none" href="#$File::Fetch::METHOD_FAIL">$File::Fetch::METHOD_FAIL</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#MAPPING">MAPPING</a> </li> <li> <a class="text-decoration-none" href="#FREQUENTLY-ASKED-QUESTIONS">FREQUENTLY ASKED QUESTIONS</a> <ul> <li> <a class="text-decoration-none" href="#So-how-do-I-use-a-proxy-with-File::Fetch?">So how do I use a proxy with File::Fetch?</a> </li> <li> <a class="text-decoration-none" href="#I-used-'lynx'-to-fetch-a-file,-but-its-contents-is-all-wrong!">I used 'lynx' to fetch a file, but its contents is all wrong!</a> </li> <li> <a class="text-decoration-none" href="#Files-I'm-trying-to-fetch-have-reserved-characters-or-non-ASCII-characters-in-them.-What-do-I-do?">Files I'm trying to fetch have reserved characters or non-ASCII characters in them. What do I do?</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#TODO">TODO</a> </li> <li> <a class="text-decoration-none" href="#BUG-REPORTS">BUG REPORTS</a> </li> <li> <a class="text-decoration-none" href="#AUTHOR">AUTHOR</a> </li> <li> <a class="text-decoration-none" href="#COPYRIGHT">COPYRIGHT</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>File::Fetch - A generic file fetching mechanism</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code>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;</code></pre> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>File::Fetch is a generic file fetching mechanism.</p> <p>It allows you to fetch any file pointed to by a <code>ftp</code>, <code>http</code>, <code>file</code>, <code>git</code> or <code>rsync</code> uri by a number of different means.</p> <p>See the <code>HOW IT WORKS</code> section further down for details.</p> <h1 id="ACCESSORS"><a class="permalink" href="#ACCESSORS">#</a>ACCESSORS</h1> <p>A <code>File::Fetch</code> object has the following accessors</p> <dl> <dt id="$ff->uri"><a class="permalink" href="#$ff-%3Euri">#</a><a id="uri"></a><a id="ff-uri"></a>$ff->uri</dt> <dd> <p>The uri you passed to the constructor</p> </dd> <dt id="$ff->scheme"><a class="permalink" href="#$ff-%3Escheme">#</a><a id="scheme"></a><a id="ff-scheme"></a>$ff->scheme</dt> <dd> <p>The scheme from the uri (like 'file', 'http', etc)</p> </dd> <dt id="$ff->host"><a class="permalink" href="#$ff-%3Ehost">#</a><a id="host"></a><a id="ff-host"></a>$ff->host</dt> <dd> <p>The hostname in the uri. Will be empty if host was originally 'localhost' for a 'file://' url.</p> </dd> <dt id="$ff->vol"><a class="permalink" href="#$ff-%3Evol">#</a><a id="vol"></a><a id="ff-vol"></a>$ff->vol</dt> <dd> <p>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.</p> <p>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 ':'.</p> <p>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.</p> </dd> <dt id="$ff->share"><a class="permalink" href="#$ff-%3Eshare">#</a><a id="share"></a><a id="ff-share"></a>$ff->share</dt> <dd> <p>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.</p> </dd> <dt id="$ff->path"><a class="permalink" href="#$ff-%3Epath">#</a><a id="path"></a><a id="ff-path"></a>$ff->path</dt> <dd> <p>The path from the uri, will be at least a single '/'.</p> </dd> <dt id="$ff->file"><a class="permalink" href="#$ff-%3Efile">#</a><a id="file"></a><a id="ff-file"></a>$ff->file</dt> <dd> <p>The name of the remote file. For the local file name, the result of $ff->output_file will be used.</p> </dd> <dt id="$ff->file_default"><a class="permalink" href="#$ff-%3Efile_default">#</a><a id="file_default"></a><a id="ff-file_default"></a>$ff->file_default</dt> <dd> <p>The name of the default local file, that $ff->output_file falls back to if it would otherwise return no filename. For example when fetching a URI like http://www.abc.net.au/ the contents retrieved may be from a remote file called 'index.html'. The default value of this attribute is literally 'file_default'.</p> </dd> <dt id="$ff->output_file"><a class="permalink" href="#$ff-%3Eoutput_file">#</a><a id="output_file"></a><a id="ff-output_file"></a>$ff->output_file</dt> <dd> <p>The name of the output file. This is the same as $ff->file, but any query parameters are stripped off. For example:</p> <pre><code class="plaintext">http://example.com/index.html?x=y</code></pre> <p>would make the output file be <code>index.html</code> rather than <code>index.html?x=y</code>.</p> </dd> </dl> <h1 id="METHODS"><a class="permalink" href="#METHODS">#</a>METHODS</h1> <h2 id="$ff-=-File::Fetch->new(-uri-=>-'http://some.where.com/dir/file.txt'-);"><a class="permalink" href="#$ff-=-File::Fetch-%3Enew(-uri-=%3E-'http://some.where.com/dir/file.txt'-);">#</a><a id="ff-File::Fetch-new-uri-http:-some.where.com-dir-file.txt"></a>$ff = File::Fetch->new( uri => 'http://some.where.com/dir/file.txt' );</h2> <p>Parses the uri and creates a corresponding File::Fetch::Item object, that is ready to be <code>fetch</code>ed and returns it.</p> <p>Returns false on failure.</p> <h2 id="$where-=-$ff->fetch(-[to-=>-/my/output/dir/-|-\$scalar]-)"><a class="permalink" href="#$where-=-$ff-%3Efetch(-%5Bto-=%3E-/my/output/dir/-%7C-%5C$scalar%5D-)">#</a><a id="where-ff-fetch-to-my-output-dir-scalar"></a>$where = $ff->fetch( [to => /my/output/dir/ | \$scalar] )</h2> <p>Fetches the file you requested and returns the full path to the file.</p> <p>By default it writes to <code>cwd()</code>, but you can override that by specifying the <code>to</code> argument:</p> <pre><code>### 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 );</code></pre> <p>Returns the full path to the downloaded file on success, and false on failure.</p> <h2 id="$ff->error([BOOL])"><a class="permalink" href="#$ff-%3Eerror(%5BBOOL%5D)">#</a><a id="error"></a><a id="ff-error-BOOL"></a>$ff->error([BOOL])</h2> <p>Returns the last encountered error as string. Pass it a true value to get the <code>Carp::longmess()</code> output instead.</p> <h1 id="HOW-IT-WORKS"><a class="permalink" href="#HOW-IT-WORKS">#</a><a id="HOW"></a>HOW IT WORKS</h1> <p>File::Fetch is able to fetch a variety of uris, by using several external programs and modules.</p> <p>Below is a mapping of what utilities will be used in what order for what schemes, if available:</p> <pre><code class="plaintext">file => LWP, lftp, file http => LWP, HTTP::Lite, wget, curl, lftp, fetch, lynx, iosock ftp => LWP, Net::FTP, wget, curl, lftp, fetch, ncftp, ftp rsync => rsync git => git</code></pre> <p>If you'd like to disable the use of one or more of these utilities and/or modules, see the <code>$BLACKLIST</code> variable further down.</p> <p>If a utility or module isn't available, it will be marked in a cache (see the <code>$METHOD_FAIL</code> variable further down), so it will not be tried again. The <code>fetch</code> method will only fail when all options are exhausted, and it was not able to retrieve the file.</p> <p>The <code>fetch</code> utility is available on FreeBSD. NetBSD and Dragonfly BSD may also have it from <code>pkgsrc</code>. We only check for <code>fetch</code> on those three platforms.</p> <p><code>iosock</code> is a very limited <a href="/5.20.0/IO::Socket::INET">IO::Socket::INET</a> based mechanism for retrieving <code>http</code> schemed urls. It doesn't follow redirects for instance.</p> <p><code>git</code> only supports <code>git://</code> style urls.</p> <p>A special note about fetching files from an ftp uri:</p> <p>By default, all ftp connections are done in passive mode. To change that, see the <code>$FTP_PASSIVE</code> variable further down.</p> <p>Furthermore, ftp uris only support anonymous connections, so no named user/password pair can be passed along.</p> <p><code>/bin/ftp</code> is blacklisted by default; see the <code>$BLACKLIST</code> variable further down.</p> <h1 id="GLOBAL-VARIABLES"><a class="permalink" href="#GLOBAL-VARIABLES">#</a><a id="GLOBAL"></a>GLOBAL VARIABLES</h1> <p>The behaviour of File::Fetch can be altered by changing the following global variables:</p> <h2 id="$File::Fetch::FROM_EMAIL"><a class="permalink" href="#$File::Fetch::FROM_EMAIL">#</a><a id="File::Fetch::FROM_EMAIL"></a>$File::Fetch::FROM_EMAIL</h2> <p>This is the email address that will be sent as your anonymous ftp password.</p> <p>Default is <code>File-Fetch@example.com</code>.</p> <h2 id="$File::Fetch::USER_AGENT"><a class="permalink" href="#$File::Fetch::USER_AGENT">#</a><a id="File::Fetch::USER_AGENT"></a>$File::Fetch::USER_AGENT</h2> <p>This is the useragent as <code>LWP</code> will report it.</p> <p>Default is <code>File::Fetch/$VERSION</code>.</p> <h2 id="$File::Fetch::FTP_PASSIVE"><a class="permalink" href="#$File::Fetch::FTP_PASSIVE">#</a><a id="File::Fetch::FTP_PASSIVE"></a>$File::Fetch::FTP_PASSIVE</h2> <p>This variable controls whether the environment variable <code>FTP_PASSIVE</code> and any passive switches to commandline tools will be set to true.</p> <p>Default value is 1.</p> <p>Note: When $FTP_PASSIVE is true, <code>ncftp</code> will not be used to fetch files, since passive mode can only be set interactively for this binary</p> <h2 id="$File::Fetch::TIMEOUT"><a class="permalink" href="#$File::Fetch::TIMEOUT">#</a><a id="File::Fetch::TIMEOUT"></a>$File::Fetch::TIMEOUT</h2> <p>When set, controls the network timeout (counted in seconds).</p> <p>Default value is 0.</p> <h2 id="$File::Fetch::WARN"><a class="permalink" href="#$File::Fetch::WARN">#</a><a id="File::Fetch::WARN"></a>$File::Fetch::WARN</h2> <p>This variable controls whether errors encountered internally by <code>File::Fetch</code> should be <code>carp</code>'d or not.</p> <p>Set to false to silence warnings. Inspect the output of the <code>error()</code> method manually to see what went wrong.</p> <p>Defaults to <code>true</code>.</p> <h2 id="$File::Fetch::DEBUG"><a class="permalink" href="#$File::Fetch::DEBUG">#</a><a id="File::Fetch::DEBUG"></a>$File::Fetch::DEBUG</h2> <p>This enables debugging output when calling commandline utilities to fetch files. This also enables <code>Carp::longmess</code> errors, instead of the regular <code>carp</code> errors.</p> <p>Good for tracking down why things don't work with your particular setup.</p> <p>Default is 0.</p> <h2 id="$File::Fetch::BLACKLIST"><a class="permalink" href="#$File::Fetch::BLACKLIST">#</a><a id="File::Fetch::BLACKLIST"></a>$File::Fetch::BLACKLIST</h2> <p>This is an array ref holding blacklisted modules/utilities for fetching files with.</p> <p>To disallow the use of, for example, <code>LWP</code> and <code>Net::FTP</code>, you could set $File::Fetch::BLACKLIST to:</p> <pre><code>$File::Fetch::BLACKLIST = [qw|lwp netftp|]</code></pre> <p>The default blacklist is [qw|ftp|], as <code>/bin/ftp</code> is rather unreliable.</p> <p>See the note on <code>MAPPING</code> below.</p> <h2 id="$File::Fetch::METHOD_FAIL"><a class="permalink" href="#$File::Fetch::METHOD_FAIL">#</a><a id="File::Fetch::METHOD_FAIL"></a>$File::Fetch::METHOD_FAIL</h2> <p>This is a hashref registering what modules/utilities were known to fail for fetching files (mostly because they weren't installed).</p> <p>You can reset this cache by assigning an empty hashref to it, or individually remove keys.</p> <p>See the note on <code>MAPPING</code> below.</p> <h1 id="MAPPING"><a class="permalink" href="#MAPPING">#</a>MAPPING</h1> <p>Here's a quick mapping for the utilities/modules, and their names for the $BLACKLIST, $METHOD_FAIL and other internal functions.</p> <pre><code class="plaintext">LWP => lwp HTTP::Lite => httplite HTTP::Tiny => httptiny Net::FTP => netftp wget => wget lynx => lynx ncftp => ncftp ftp => ftp curl => curl rsync => rsync lftp => lftp fetch => fetch IO::Socket => iosock</code></pre> <h1 id="FREQUENTLY-ASKED-QUESTIONS"><a class="permalink" href="#FREQUENTLY-ASKED-QUESTIONS">#</a><a id="FREQUENTLY"></a>FREQUENTLY ASKED QUESTIONS</h1> <h2 id="So-how-do-I-use-a-proxy-with-File::Fetch?"><a class="permalink" href="#So-how-do-I-use-a-proxy-with-File::Fetch?">#</a><a id="So"></a><a id="So-how-do-I-use-a-proxy-with-File::Fetch"></a>So how do I use a proxy with File::Fetch?</h2> <p><code>File::Fetch</code> currently only supports proxies with LWP::UserAgent. You will need to set your environment variables accordingly. For example, to use an ftp proxy:</p> <pre><code>$ENV{ftp_proxy} = 'foo.com';</code></pre> <p>Refer to the LWP::UserAgent manpage for more details.</p> <h2 id="I-used-'lynx'-to-fetch-a-file,-but-its-contents-is-all-wrong!"><a class="permalink" href="#I-used-'lynx'-to-fetch-a-file,-but-its-contents-is-all-wrong!">#</a><a id="I"></a><a id="I-used-lynx-to-fetch-a-file-but-its-contents-is-all-wrong"></a>I used 'lynx' to fetch a file, but its contents is all wrong!</h2> <p><code>lynx</code> can only fetch remote files by dumping its contents to <code>STDOUT</code>, which we in turn capture. If that content is a 'custom' error file (like, say, a <code>404 handler</code>), you will get that contents instead.</p> <p>Sadly, <code>lynx</code> doesn't support any options to return a different exit code on non-<code>200 OK</code> status, giving us no way to tell the difference between a 'successful' fetch and a custom error page.</p> <p>Therefor, we recommend to only use <code>lynx</code> as a last resort. This is why it is at the back of our list of methods to try as well.</p> <h2 id="Files-I'm-trying-to-fetch-have-reserved-characters-or-non-ASCII-characters-in-them.-What-do-I-do?"><a class="permalink" href="#Files-I'm-trying-to-fetch-have-reserved-characters-or-non-ASCII-characters-in-them.-What-do-I-do?">#</a><a id="Files"></a><a id="Files-Im-trying-to-fetch-have-reserved-characters-or-non-ASCII-characters-in-them.-What-do-I-do"></a>Files I'm trying to fetch have reserved characters or non-ASCII characters in them. What do I do?</h2> <p><code>File::Fetch</code> is relatively smart about things. When trying to write a file to disk, it removes the <code>query parameters</code> (see the <code>output_file</code> method for details) from the file name before creating it. In most cases this suffices.</p> <p>If you have any other characters you need to escape, please install the <code>URI::Escape</code> module from CPAN, and pre-encode your URI before passing it to <code>File::Fetch</code>. You can read about the details of URIs and URI encoding here:</p> <pre><code class="plaintext">http://www.faqs.org/rfcs/rfc2396.html</code></pre> <h1 id="TODO"><a class="permalink" href="#TODO">#</a>TODO</h1> <dl> <dt id="Implement-$PREFER_BIN"><a class="permalink" href="#Implement-$PREFER_BIN">#</a><a id="Implement"></a><a id="Implement-PREFER_BIN"></a>Implement $PREFER_BIN</dt> <dd> <p>To indicate to rather use commandline tools than modules</p> </dd> </dl> <h1 id="BUG-REPORTS"><a class="permalink" href="#BUG-REPORTS">#</a><a id="BUG"></a>BUG REPORTS</h1> <p>Please report bugs or other issues to <bug-file-fetch@rt.cpan.org<gt>.</p> <h1 id="AUTHOR"><a class="permalink" href="#AUTHOR">#</a>AUTHOR</h1> <p>This module by Jos Boumans <kane@cpan.org>.</p> <h1 id="COPYRIGHT"><a class="permalink" href="#COPYRIGHT">#</a>COPYRIGHT</h1> <p>This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.</p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>