(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30, show_progress = False, tqdm_kwargs = { })
| 1050 | self._storeFileFromOffset_SMB2(service_name, path, file_obj, callback, errback, 0, True, timeout) |
| 1051 | |
| 1052 | def _storeFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, truncate = False, timeout = 30, show_progress = False, tqdm_kwargs = { }): |
| 1053 | if not self.has_authenticated: |
| 1054 | raise NotReadyError('SMB connection not authenticated') |
| 1055 | |
| 1056 | expiry_time = time.time() + timeout |
| 1057 | path = path.replace('/', '\\') |
| 1058 | if path.startswith('\\'): |
| 1059 | path = path[1:] |
| 1060 | if path.endswith('\\'): |
| 1061 | path = path[:-1] |
| 1062 | messages_history = [ ] |
| 1063 | |
| 1064 | if show_progress: |
| 1065 | total_bytes = os.stat(file_obj.name).st_size |
| 1066 | tqdm_kwargs.setdefault("total", total_bytes) |
| 1067 | tqdm_kwargs.setdefault("unit", "B") |
| 1068 | tqdm_kwargs.setdefault("unit_scale", True) |
| 1069 | tqdm_kwargs.setdefault("unit_divisor", 1024) |
| 1070 | tqdm_kwargs.setdefault("desc", f"Uploading {path}") |
| 1071 | self.pbar = tqdm(**tqdm_kwargs) |
| 1072 | def sendCreate(tid): |
| 1073 | create_context_data = binascii.unhexlify(b""" |
| 1074 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 |
| 1075 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1076 | 00 00 00 00 00 00 00 00 20 00 00 00 10 00 04 00 |
| 1077 | 00 00 18 00 08 00 00 00 41 6c 53 69 00 00 00 00 |
| 1078 | 85 62 00 00 00 00 00 00 18 00 00 00 10 00 04 00 |
| 1079 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 |
| 1080 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 |
| 1081 | 51 46 69 64 00 00 00 00 |
| 1082 | """.replace(b' ', b'').replace(b'\n', b'')) |
| 1083 | m = SMB2Message(SMB2CreateRequest(path, |
| 1084 | file_attributes = ATTR_ARCHIVE, |
| 1085 | access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | FILE_READ_EA | FILE_WRITE_EA | READ_CONTROL | SYNCHRONIZE, |
| 1086 | share_access = 0, |
| 1087 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
| 1088 | impersonation = SEC_IMPERSONATE, |
| 1089 | create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE, |
| 1090 | create_disp = FILE_OVERWRITE_IF if truncate else FILE_OPEN_IF, |
| 1091 | create_context_data = create_context_data)) |
| 1092 | m.tid = tid |
| 1093 | self._sendSMBMessage(m) |
| 1094 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) |
| 1095 | self._pushToArray(messages_history, m) |
| 1096 | |
| 1097 | def createCB(create_message, **kwargs): |
| 1098 | create_message.tid = kwargs['tid'] |
| 1099 | self._pushToArray(messages_history, create_message) |
| 1100 | if create_message.status == 0: |
| 1101 | sendWrite(create_message.tid, create_message.payload.fid, starting_offset) |
| 1102 | else: |
| 1103 | errback(OperationFailure('Failed to store %s on %s: Unable to open file' % ( path, service_name ), messages_history)) |
| 1104 | |
| 1105 | def sendWrite(tid, fid, offset): |
| 1106 | write_count = self.max_write_size |
| 1107 | data = file_obj.read(write_count) |
| 1108 | data_len = len(data) |
| 1109 | if data_len > 0: |
no test coverage detected