getLatestFTP.py 这个程序用于下载网站中最新版本的文件。你可以修改这个程序让它下载你喜欢的程序 ''' Created on 2010-12-15 @author: Administrator ''' import ftplib import os import socket HOST='ftp.mozilla.org' DIRN='pub/mozilla.org/webtools' FILE='bugzilla-LATEST.tar.gz' def main(): try: f=ftplib.FTP(HOST) except (socket.error,socket.gaierror),e: print 'Error: can not reach "%s"' %HOST return print '*** connected to host "%s"' %HOST try: f.login() except ftplib.error_perm: print 'ERROR: can not login anonymously' f.quit() return print '***Logged in as "anonymous"' try: f.cwd(DIRN) except ftplib.error_perm: print 'ERROR: can not CD to "%s"' % DIRN f.quit() return print '***Changed to "%s" folder' % DIRN try: f.retrbinary('RETR %s' %FILE, open(FILE,'wb').write) except ftplib.error_perm: print 'ERROR: can not read file "%s"' % FILE os.unlink(FILE) else: print '***Downloaded "%s" to CWD' %FILE f.quit() return if __name__=='__main__': main()