technovelty

weblog of Ian Wienand

RSS  |  technovelty home  |  page of ian  |  ian@wienand.org

the magic of netrc

If you're like me, you probably use ftp every day but have never read the man page. I wish I had though, because it reveals the netrc(5) file for automating logins, and even simple macros.

machine ftp.machine.com
	login ianw
	password password
	macdef upload
	       cd /public_html/a/dir
	       lcd /var/www/a/dir
	       mput blah.txt

machine ftp.machine2.com ...

Actually, I only found out about this because the Python ftplib code mentions it. So you can do something like

from ftplib import FTP
from netrc import netrc

(username,account,password) = netrc().authenticators('ftp.machine.org')

ftp = FTP('ftp.machine.org')
ftp.set_debuglevel(2)
ftp.login(username, password)

It's always nifty re-discovering something that has been around since the dawn of time_t!

posted at: Thu, 26 May 2005 13:32 | in /linux/tips | permalink | add comment (0 others)

Add a comment
*Name
*Email (not shown)
Website
*Comment:
Anti-spam:
* denotes required field

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.