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