python3 FTP简单实现文件下载(含中文乱码问题)

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