• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

雇的辣客

雇的辣客
  • 博客园
  • 联系
  • 管理

公告

View Post

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

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

 

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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")

posted on 2020-04-01 20:27  雇的辣客  阅读(371)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3