Saleh
Saleh

Reputation: 1931

Download a giant file with HTTP and upload to FTP server without storing it

I have a project which I should download some giant files using HTTP and upload them to am FTP server. The simplest way is to first download the file and then upload it to FTP; Thinking it as two independent stages.

But can we use streams to upload the file as it is being downloaded? This way seems more efficient. Any example specially in python are welcome.

Upvotes: 1

Views: 565

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202494

Use requests module to obtain a file-like object representing the HTTP download and use it with ftplib FTP.storbinary:

from ftplib import FTP
import requests 

url = "https://www.example.com/file.zip"
r = requests.get(url, stream=True)
ftp = FTP(host, user, passwd)
ftp.storbinary("STOR /ftp/path/file.zip", r.raw)

Upvotes: 1

Related Questions