Python Core Programming (3rd Edition)-Client FTP program sample

Source: Internet
Author: User

cat getlatestftp.py#!/usr/bin/pythonimport ftplibimport osimport sockethost =  ' 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)  as e:         print  ' error:cannot reach  '%s '  % HOST         return    print  ' *** connected to  host  '%s '  % HOST    try:         F.login (' web2 ', ' she3t6net6hv3 ')     except ftplib.error_perm:         print  ' error: cannot login anonymously '          f.quit()         return    print  ' *** logged  in as  "Anonymous"     try:         F.CWD (Dirn)     except ftplib.error_perm:         print  ' error:cannot 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:cannot read file   "%s" '  % fIle        if os.path.exists (FILE):             os.unlink (FILE)         else:             print  ' *** downloaded  ' %s " TO CWD '  % file    f.quit () if __name__ ==  ' __main__ ' :     main ()

Summarize:

The 1,ftp.mozilla.org is no longer accessible.

2, the relevant variables are modified according to the actual situation, Host,dirn,file.

3, this content is in "Python Core programming (3rd Edition)" 79th page.


Python Core Programming (3rd Edition)-Client FTP program sample

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.