使用Paramiko将PIL图像保存到SFTP文件夹(PNG或PDF)

发布于 2025-01-20 04:19:22 字数 401 浏览 3 评论 0原文

我需要您的帮助,使用以下示例将 PIL“图像”保存到服务器(SFTP):

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()

但它不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人疚 2025-01-27 04:19:22

我相信你应该使用 图像。 save

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

有关 32768 参数的用途,请参阅写入使用 Paramiko/pysftp“打开”方法打开的 SFTP 服务器上的文件很慢

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文