有大神知道怎么使用python 往ftp服务器上连续上传下载多张图片吗?
1个回答
展开全部
例:下载、上传文件
# coding: utf-8
from ftplib import FTP
import time
import tarfile
import os
# !/usr/bin/python
# -*- coding: utf-8 -*-
from ftplib import FTP
def ftpconnect(host, username, password):
ftp = FTP()
# ftp.set_debuglevel(2)
ftp.connect(host, 21)
ftp.login(username, password)
return ftp
#从ftp下载文件
def downloadfile(ftp, remotepath, localpath):
bufsize = 1024
fp = open(localpath, 'wb')
ftp.retrbinary('RETR ' + remotepath, fp.write, bufsize)
ftp.set_debuglevel(0)
fp.close()
#从本地上传文件到ftp
def uploadfile(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 = ftpconnect("113.105.139.xxx", "ftp***", "Guest***")
downloadfile(ftp, "Faint.mp4", "C:/Users/Administrator/Desktop/test.mp4")
#调用本地播放器播放下载的视频
os.system('start "C:\Program Files\Windows Media Player\wmplayer.exe" "C:/Users/Administrator/Desktop/test.mp4"')
uploadfile(ftp, "C:/Users/Administrator/Desktop/test.mp4", "test.mp4")
ftp.quit()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询