Failing to pass a downloaded file-like object from sharepoint using the shareplum and paramiko libraries

34 Views Asked by At

I'm receiving an error when passing a file object using paramiko's putfo().

AttributeError: 'bytes' object has no attribute 'read'

Here's what my putfo() looks like

ssh_client = paramiko.SSHClient()

ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=host, port=port, username=username,password=password, look_for_keys=False)

ftp = ssh_client.open_sftp()

ftp.putfo(file_obj, remotepath=file_name)

file_obj is downloaded to memory using shareplum's get_file()

I'm unfamiliar what I should try here to solve this problem.

1

There are 1 best solutions below

1
Asish M. On BEST ANSWER

putfo requires a file or file-like object. The error message indicates you're getting raw bytes instead of a file io (raw bytes don't have a read method, but file-io objects do).

To address that, wrap your returned bytes using io.BytesIO

from io import BytesIO
ftp.putfo(BytesIO(file_obj), remotepath=file_name)