Python implementation ftp upload download code (with error handling)

Source: Internet
Author: User

#-*-coding:utf-8-*-#python#Xiaodeng#python implementation ftp upload download code (with error handling)#Http://www.cnblogs.com/kaituorensheng/p/4480512.html#_label2ImportFtplibImportSocketImportOSdefFtpconnect (ftp_info):Try: FTP=Ftplib. FTP (ftp_info[0])except(Socket.error, socket.gaierror):Print "Error:cannot reach%s"%Ftp_info[0]returnNone username= Ftp_info[1] passwd= Ftp_info[2]    Try: Ftp.login (username, passwd)exceptFtplib.error_perm:Print "Error:cannot Login anonymously"ftp.quit ()returnNonereturnFTPif __name__=="__main__": Ftp_info= ["10.19.3.199","Fastupdate_amap","@utonavi &a.map"] FTP=Ftpconnect (ftp_info)if  notFtp:exit (1) BufSize= 1024fname="20150416113942674.tar.gz"FP= Open (Os.path.join (".", fname),'WB') RemoteFile= Os.path.join ("/adf++", fname) ftp.retrbinary ("RETR"+remotefile, Fp.write, bufsize)#If there is a directory, do not create, or if you have permission to createA =Ftp.dir ()Try: FTP.CWD ("Jimi")    exceptFtplib.error_perm:Try: FTP.MKD ("Jimi")        exceptFtplib.error_perm:Print "You has no authority to make Dir"    finally: Ftp.quit ()

Python implementation ftp upload download code (with error handling)

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.