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!