MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / retrieveFileFromOffset

Method retrieveFileFromOffset

pager_lib/smb/SMBConnection.py:326–362  ·  view source on GitHub ↗

Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*. :param string/unicode service_name: the name of the shared folder for the *path* :param string/unicode path: Path of the file on the remote server. If the

(self, service_name, path, file_obj, offset = 0, max_length = -1, timeout = 30, show_progress = False, tqdm_kwargs = {})

Source from the content-addressed store, hash-verified

324 return self.retrieveFileFromOffset(service_name, path, file_obj, 0, -1, timeout, show_progress = show_progress, tqdm_kwargs = tqdm_kwargs)
325
326 def retrieveFileFromOffset(self, service_name, path, file_obj, offset = 0, max_length = -1, timeout = 30, show_progress = False, tqdm_kwargs = {}):
327 """
328 Retrieve the contents of the file at *path* on the *service_name* and write these contents to the provided *file_obj*.
329
330 :param string/unicode service_name: the name of the shared folder for the *path*
331 :param string/unicode path: Path of the file on the remote server. If the file cannot be opened for reading, an :doc:`OperationFailure<smb_exceptions>` will be raised.
332 :param file_obj: A file-like object that has a *write* method. Data will be written continuously to *file_obj* up to *max_length* number of bytes. In Python3, this file-like object must have a *write* method which accepts a bytes parameter.
333 :param integer/long offset: the offset in the remote *path* where the first byte will be read and written to *file_obj*. Must be either zero or a positive integer/long value.
334 :param integer/long max_length: maximum number of bytes to read from the remote *path* and write to the *file_obj*. Specify a negative value to read from *offset* to the EOF.
335 If zero, the method returns immediately after the file is opened successfully for reading.
336 :param bool show_progress: If True, a progress bar will be shown to reflect the current file operation progress.
337 :return: A 2-element tuple of ( file attributes of the file on server, number of bytes written to *file_obj* ).
338 The file attributes is an integer value made up from a bitwise-OR of *SMB_FILE_ATTRIBUTE_xxx* bits (see smb_constants.py)
339 """
340 if not self.sock:
341 raise NotConnectedError('Not connected to server')
342
343 results = [ ]
344
345 def cb(r):
346 self.is_busy = False
347 results.append(r[1:])
348
349 def eb(failure):
350 self.is_busy = False
351 raise failure
352
353 self.is_busy = True
354
355 try:
356 self._retrieveFileFromOffset(service_name, path, file_obj, cb, eb, offset, max_length, timeout = timeout, show_progress=show_progress, tqdm_kwargs=tqdm_kwargs)
357 while self.is_busy:
358 self._pollForNetBIOSPacket(timeout)
359 finally:
360 self.is_busy = False
361
362 return results[0]
363
364 def storeFile(self, service_name, path, file_obj, timeout = 30, show_progress = False, tqdm_kwargs = {}):
365 """

Callers 1

retrieveFileMethod · 0.95

Calls 2

_pollForNetBIOSPacketMethod · 0.95
NotConnectedErrorClass · 0.70

Tested by

no test coverage detected