>>> from ftplib import FTP >>> ftp = FTP('ftp.cwi.nl') # connect to host, default port >>> ftp.login() # user anonymous, passwd user@hostname "230-\012 230- ************\012 230- * *\012 230- * Ftp.cwi.nl welcomes you from: yourhost.yourdomain\012 230- * The time is ... " >>> ftp.cwd('pub/python') '250 CWD command successful.' >>> ftp.retrlines('LIST') # list directory contents total 142 drwxrwsr-x 20 ftp-usr pdmaint 4096 Jan 21 23:56 . dr-xr-xrwt 149 ftp-usr pdmaint 4096 Feb 17 15:02 .. -rw-r--r-- 1 ftp-usr pdmaint 91 Jan 4 01:01 .mirrorinfo drwxr-sr-x 2 ftp-usr pdmaint 9 Nov 19 1996 RCS -rw-r--r-- 1 ftp-usr pdmaint 1712 Nov 19 23:54 README drwxr-sr-x 2 ftp-usr pdmaint 75 Jan 4 01:01 binaries-1.4 drwxr-sr-x 2 ftp-usr pdmaint 4096 Jan 4 01:01 binaries-1.5 . . . >>> ftp.retrascii('RETR README') Python Distribution =================== Most subdirectories have a README or INDEX files explaining the contents. . . . >>> # Retrieve a binary file >>> filename = 'python-gdbm-1.5-2.i386.rpm' >>> f=open(filename, 'w') >>> ftp.retrbinary('RETR binaries-1.5/' + filename, f.write) '226 Transfer complete.' >>> f.close() >>> # End the session >>> ftp.quit()