Python中通过流上传下载文件

admin 2020-5-29 13792

给段示例代码:

------------------

import ftplib as ftp
from io import BytesIO

ftp_one=ftp.FTP(address1, user1, pass1)
ftp_two=ftp.FTP(address2, user2, pass2)
myfile=BytesIO()
ftp_one.retrbinary ('RETR imageoldname.jpg', myfile.write)
myfile.seek(0)    #这一句很重要,不执行则后面取不到数据
ftp_two.storbinary('STOR imagenewname.jpg', myfile)
ftp_one.close()
ftp_two.close()
myfile.close()


参考:

https://stackoverflow.com/questions/16991819/ftp-sending-python-bytesio-stream

https://stackoverflow.com/questions/11208957/is-it-possible-to-read-ftp-files-without-writing-them-using-python

https://stackoverflow.com/questions/51024276/python-stream-from-ftp-server-to-flask-server-for-downloading

http://theautomatic。net/2017/09/29/downloading-every-file-ftp-server/



最新回复 (0)
返回