FTP for python Network Programming

Source: Internet
Author: User

 

 

Getlatestftp. py

 

This program is used to download the latest version of the website. You can modify this program to download your favorite program.

 

 

''' <Br/> created on 2010-12-15 <br/> @ Author: administrator <br/> ''' <br/> Import ftplib <br/> Import OS <br/> Import socket <br/> host = 'ftp .w.illa.org '<br/> dirn = 'pub/javasilla.org/webtools' <br/> file+'bugzilla-latest.tar.gz '<br/> def main (): <br/> try: <br/> F = ftplib. FTP (host) <br/> socket T (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/> using t 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/> small T 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/> using t 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> 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.