python 3 FTPは簡単にファイルのダウンロードを実現します(中国語の文字化け問題を含みます)

624 ワード

原文のリンク:http://www.cnblogs.com/mahailuo/p/8615604.html
from ftplib import FTP
def ftp_down(HOST,romatepath,filename,localpath):
  user=*****
  password=*****
  ftp=FTP(HOST)#       IP  
  ftp.encoding = 'utf-8'#        
  ftp.login(user,password)
  #print (ftp.getwelcome())#  ftp       
  ftp.cwd(romatepath)#      
  bufsize = 1024
  file_handler = open(localpath,'wb').write  #           
  ftp.retrbinary('RETR %s' % filename,file_handler,bufsize)
  ftp.quit()
  print ("ftp down OK")
  
  
転載先:https://www.cnblogs.com/mahailuo/p/8615604.html