python3操作ftp
2021-03-09 14:27
标签:orb rgb login 切换 coding bsp upload tor 下载 ftp相关的包不需要安装,python自带 python3操作ftp 标签:orb rgb login 切换 coding bsp upload tor 下载 原文地址:https://www.cnblogs.com/lingwang3/p/14179681.html# -*- coding:utf-8 -*-
from ftplib import FTP
def upload(f, remote_path, local_path):
fp = open(local_path, "rb")
buf_size = 1024
f.storbinary("STOR {}".format(remote_path), fp, buf_size)
fp.close()
def download(f, remote_path, local_path):
fp = open(local_path, "wb")
buf_size = 1024
f.retrbinary(‘RETR {}‘.format(remote_path), fp.write, buf_size)
fp.close()
if __name__ == "__main__":
ftp = FTP()
ftp.connect("172.31.160.51", 21)
ftp.login("用户名", "密码")
ftp.cwd("download/20201223ftp") #切换到ftp的某个目录下
upload(ftp, "code_1.js", "code.js") #将本地code.js文件上传到ftp,并且重命名为code_1.js
download(ftp, "code_1.js", "code_2.js") #将ftp的code_1.js下载的本地,命名为code_2.js
ftp.quit()
上一篇:java字符串多行写法