Python实现FTP⽂件的上传和下载# coding: utf-8爸爸去哪儿最后一期
import os
from ftplib import FTP
def ftp_connect(host, username, password):
ftp = FTP()
# ftp.set_debuglevel(2)博客上传视频
ftp.login(username, password)
return ftp
"""
从ftp服务器下载⽂件
"""
陈倩扬老公def download_file(ftp, remotepath, localpath):
bufsize = 1024
fp = open(localpath, 'wb')
ftp.set_debuglevel(0)
fp.close()
"""
从本地上传⽂件到ftp
"""
def upload_file(ftp, remotepath, localpath):
苍井空八卦斯坦李bufsize = 1024
fp = open(localpath, 'rb')
ftp.storbinary('STOR ' + remotepath, fp, bufsize)
ftp.set_debuglevel(0)潘虹演的电视剧
fp.close()
if__name__ == "__main__":
ftp = ftp_connect("1.211.11.79", "XXXX", "123456")
download_file(ftp, r"IMG_0682.jpg", r"C:\Users\lenovo\Desktop\最新接⼝\img.jpg")
#调⽤本地播放器播放下载的视频
os.system('start "C:\Program Files\Windows Media " "C:/Users/Administrator/Desktop/test.mp4"')
upload_file(ftp, r"IMG_0682.jpg", "E:\我们的照⽚\新建件夹\IMG_0682.jpg")
ftp.quit()