Net::Netrc(3pm)

πŸ’… Net::Netrc β€” the OO interface to your netrc file, bestie ✨

okay so real quick: this is a page from the Perl Programmers Reference Guide (yes, the fancy one πŸŽ€). Let's get into it.


🌸 NAME 🌸

Net::Netrc β€” an OO interface to users' netrc file πŸ—‚οΈβœ¨


πŸ¦‹ SYNOPSIS πŸ¦‹

use Net::Netrc;

$mach = Net::Netrc->lookup('some.machine');
$login = $mach->login;
($login, $password, $account) = $mach->lpa;

like… that's it. that's the whole vibe. 🫢


πŸ’– DESCRIPTION πŸ’–

Net::Netrc is a class that implements a simple interface to the .netrc file β€” the same one the ftp program uses. iconic behavior honestly πŸ‘‘

And get this: Net::Netrc also implements security checks, just like the ftp program does. There are two of them, so listen up πŸ”₯:

  1. the .netrc file must be owned by the user, and
  2. the ownership permissions have to be set so that only the owner has read and write access.
🚨 if those conditions are not met, a warning gets output and the .netrc file is not read. no cap, it just refuses. πŸ’€

πŸŽ€ The .netrc File πŸŽ€

The .netrc file holds all the login and initialization info that the auto-login process uses. It lives in the user's home directory. 🏠

These are the tokens it recognizes β€” and they can be separated by spaces, tabs, or new-lines, so like, format it however, she's flexible ✨:

  • machine name β€” identifies a remote machine name. The auto-login process searches the .netrc file for a machine token matching the remote machine you specified. Once a match happens, the subsequent .netrc tokens get processed, and it stops when it hits end of file, another machine token, or a default token. πŸ›‘
  • default β€” same deal as machine name, except default matches any name. There can be only one default token, and it must come after all the machine tokens. Normally it's used like this:
default login anonymous password user@site

which gives you automatic anonymous login to machines that aren't specified in .netrc 🫢

  • login name β€” identifies a user on the remote machine. If this token is present, the auto-login process will initiate a login using the specified name.
  • password string β€” supplies a password. If this token is present, the auto-login process will supply the specified string if the remote server requires a password as part of the login process πŸ”
  • account string β€” supplies an additional account password. If this token is present, the auto-login process will supply the specified string if the remote server requires an additional account password.
  • macdef name β€” defines a macro. Net::Netrc only parses this field to be compatible with ftp. that's literally all she does with it, don't @ me πŸ™ˆ

⭐ Class Methods ⭐

okay so the constructor for a Net::Netrc object is not called new, because it doesn't really create a new object. Instead it's called lookup, because that's essentially what it does. main character naming energy πŸ‘‘

πŸ’œ lookup($machine[, $login])

Lookup and return a reference to the entry for $machine. If $login is given, then the entry returned will have the given login. If $login is not given, then the first entry in the .netrc file for $machine gets returned. 🎯

If a matching entry can't be found, and a default entry exists, then a reference to the default entry is returned.

If there's no matching entry found and there's no default defined, or no .netrc file is found, then undef is returned. 😭


🌈 Object Methods 🌈

🌸 login()

Return the login id for the netrc entry πŸͺͺ

🌸 password()

Return the password for the netrc entry πŸ”‘

🌸 account()

Return the account information for the netrc entry πŸ“‹

🌸 lpa()

Return a list of login, password and account information for the netrc entry. all three at once, she's efficient πŸ’…


🧚 EXPORTS 🧚

None. nothing. zero. nada. don't come looking 🚫


πŸ’€ KNOWN BUGS πŸ’€

See https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet.


πŸ”₯ SEE ALSO πŸ”₯

Net::Cmd.


πŸ‘‘ AUTHOR πŸ‘‘

Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.

Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining libnet as of version 1.22_02. the torch has been passed 🫢


Copyright (C) 1995-1998 Graham Barr. All rights reserved.

Copyright (C) 2013-2014, 2020 Steve Hay. All rights reserved.


πŸ“ LICENCE πŸ“

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e. under the terms of either the GNU General Public License or the Artistic License, as specified in the LICENCE file. πŸ“œ


⭐ VERSION ⭐

Version 3.15


πŸ¦‹ DATE πŸ¦‹

20 March 2023


πŸ’– HISTORY πŸ’–

See the Changes file.


✨ and that's the whole page, bestie! this one's from perl v5.42.3, dated 2026-11-03 β€” so go forth, read your .netrc, keep those perms tight, and slay πŸ’…πŸ‘‘
πŸ“¦ where this page comes from