1

I need your help to save a PIL "image" to a server (SFTP) using the following example:

transport = paramiko.Transport((host, port))
transport.connect(username=user, password=pwd)
sftp = paramiko.SFTPClient.from_transport(transport)

w, h = 220, 190
image = Image.new("RGB", (w, h))

file = sftp.file("/volume/file.png", "w", -1) # the volume folder is located in the server
file.write(image)
file.flush()

But it does not work.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
yasquare
  • 11
  • 2

1 Answers1

1

I believe you should use Image.save:

with sftp.open("/volume/file.png", "w", 32768) as fp:
    image.save(fp)

For the purpose of the 32768 parameter, see Writing to a file on SFTP server opened using Paramiko/pysftp "open" method is slow.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992