Python Module ftplib (Implementation of FTP upload download code)

Source: Internet
Author: User

#-*-coding:utf-8-*-#python#Xiaodeng#Python module ftplib (Implementation of FTP upload download code)#Requirements: Implement FTP upload download code (without error handling) fromFtplibImportFTPdefftpconnect (): Ftp_server='ftp.python.org'FTP=FTP () ftp.set_debuglevel (2)#turn on the mode level 2Ftp.connect (ftp_server,21) Ftp.login ("',"')#Username,password    returnFTP#implementation of the downloaddefdownloadfile (): Path='/home/static/test.jpeg'#view the path to the file you want to downloadftp=Ftpconnect ()Printftp.getwelcome () bufsize=1024#Set buffer block sizeLocalpath='D:\test2\dog.jpeg'#where to download the fileFp=open (LocalPath,'WB')    #note the space behind the RETRFtp.retrbinary ('RETR'+path,fp.write,bufsize)#receive files on the server and write to localftp.set_debuglevel (0) Fp.close () ftp.quit ()#implementation of uploadsdefuploadfile (): Path='/home/static/test.jpeg'FTP=ftpconnect () bufsize=1024LocalPath='D:\test2\dog.jpeg'FP=open (LocalPath,'RB')    #note the space behind the StorFtp.storbinary ('STOR'+path,fp,bufsize)#Uploading Filesfp.close () ftp.quit ( )if __name__=="__main__": FTP= Ftpconnect ("',"',"') DownloadFile (FTP,"',"') UploadFile (FTP,"',"') Ftp.quit ()#from: tianzhu123    

Python Module ftplib (Implementation of FTP upload download code)

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.