Overview
A netrc file is used to hold credentials necessary to login to your labkey server and authorize access to data stored there. The netrc file contains configuration and autologin information for the File Transfer Protocol client (FTP) and other programs. It may be used when working with SAS Macros, Using Java for Programmatic QC Scripts or using the Rlabkey package.
If you receive "unauthorized" error messages when trying to retrieve data from a remote server you should check that your netrc file is configured correctly, you have an entry for that remote machine, and the login credentials are correct.
Set up a .netrc or _netrc file
On a UNIX or Linux system this file should be named .netrc (dot netrc) and on Windows it should be named_netrc (underscore netrc). The file should be located in your home directory and the permissionson the file should be unreadable for everyone except you.
To create the _netrc on a Windows machine, first create an environment variable called ’HOME’that is set to your home directory (c:/Users/<User-Name> on Vista or Windows 7) or any directory you want touse. Two equivalent examples:
SET HOME="C:\Program Files\r\R-2.10\library"
SET HOME=C:\Program Files\r\R-2.10\library
In that directory, create a text file named _netrc (note that it is underscore netrc, not dot netrclike it is on UNIX).
The following three lines must be included in the .netrc or _netrc file. They must be separated by either white space(spaces, tabs, or newlines) or commas:
machine <remote-instance-of-labkey-server>
login <user-email>
password <user-password>
One example would be:
machine mymachine.labkey.org
login [email protected]
password mypassword
Another example would be:
machine mymachine.labkey.org login [email protected] password mypassword
The _netrc file only deals with connections at the machine level and does not include a port or protocol designation.
例子:
$family = 'testftp';
$machine = Net::Netrc->lookup($family);
$user = $$machine{'login'};
if ( !defined $user ) {
print "Error, no entry .netrc for server $family\n";
}
$passwd = $$machine{'password'};
if ( !defined $passwd ) {
print "Error, no password defined in .netrc for server $family\n";
}
print "user:$user passwd:$passwd\n";