jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
309 stars 72 forks source link

how to load a numpy file on smb #244

Closed talenz closed 8 months ago

talenz commented 8 months ago

Take "\10.10.50.1\tmp.np" as a example.

with smbclient.open_file(r"\\10.10.50.1\tmp.np", mode='rb') as fl: x = np.load(fl, allow_pickle=True)

Not Working!!

jborean93 commented 8 months ago

I don’t really know numpy but how do you do it with a local file? What’s the error that you get with the example code you’ve shared.

talenz commented 8 months ago

With a local file, just use numpy.load("tmp.npy")

The Error is array = numpy.fromfile(fp, dtype=dtype, count=count) io.UnsupportedOperation: fileno

talenz commented 8 months ago

I don’t really know numpy but how do you do it with a local file? What’s the error that you get with the example code you’ve shared.

This works~ `from smbclient._io import ( SMBDirectoryIO, SMBFileIO, SMBFileTransaction, SMBPipeIO, SMBRawIO, ioctl_request, query_info, set_info, )

smbclient.register_session("10.10.50.1")

file_class = { "file": SMBFileIO, "dir": SMBDirectoryIO, "pipe": SMBPipeIO, }["file"]

raw_fd = file_class( r"\10.10.50.1\tmp.np", mode="rb", share_access=None, desired_access=None, file_attributes=None, )

raw_fd.open() x = np.load(raw_fd)`

jborean93 commented 8 months ago

You can avoid all that extra work by just opening the raw smb_file by turning off buffering

import smbclient

with smbclient.open_file(r'\\server\share\file.tmp', mode='rb', buffering=0) as fd:
    np.load(fd)