0

I have many images stored in an ftp server.

I would like to avoid downloading all the images, but just load them from the ftp using PIL, like that:

from PIL import Image
img = Image.open("ftp://myftp.com/dir/myimage.bmp")

It does not work this way (No such file or directory).

How can I do this without downloading in a temporary file ?

I am using python 3.8.

dagnic
  • 137
  • 10

1 Answers1

2

Following @MauriceMeyer, I did the following, that works.

from PIL import Image
from io import BytesIO
from ftplib import FTP
ftp = FTP("myftp.com")
ftp.login("me", "mypwd")
flo = BytesIO()
ftp.retrbinary('RETR dir/myimage.bmp', flo.write)
flo.seek(0)
img = Image.open(flo)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
dagnic
  • 137
  • 10