MCPcopy Create free account
hub / github.com/aitjcize/Overlord / HandleFileUploadRequest

Method HandleFileUploadRequest

py/ghost.py:1029–1075  ·  view source on GitHub ↗
(self, msg)

Source from the content-addressed store, hash-verified

1027 self.SendResponse(msg, SUCCESS)
1028
1029 def HandleFileUploadRequest(self, msg):
1030 payload = msg['payload']
1031
1032 # Resolve upload filepath
1033 filename = payload['filename']
1034 dest_path = filename
1035
1036 # If dest is specified, use it first
1037 dest_path = payload.get('dest', '')
1038 if dest_path:
1039 if not os.path.isabs(dest_path):
1040 dest_path = os.path.join(os.getenv('HOME', '/tmp'), dest_path)
1041
1042 if os.path.isdir(dest_path):
1043 dest_path = os.path.join(dest_path, filename)
1044 else:
1045 target_dir = os.getenv('HOME', '/tmp')
1046
1047 # Terminal session ID found, upload to it's current working directory
1048 if 'terminal_sid' in payload:
1049 pid = self._terminal_sid_to_pid.get(payload['terminal_sid'], None)
1050 if pid:
1051 try:
1052 target_dir = self.GetProcessWorkingDirectory(pid)
1053 except Exception as e:
1054 logging.error(e)
1055
1056 dest_path = os.path.join(target_dir, filename)
1057
1058 try:
1059 os.makedirs(os.path.dirname(dest_path))
1060 except Exception:
1061 pass
1062
1063 try:
1064 with open(dest_path, 'wb', encoding=None):
1065 pass
1066 except Exception as e:
1067 self.SendErrorResponse(msg, str(e))
1068 return
1069
1070 # If not check_only, spawn FILE mode ghost agent to handle upload
1071 if not payload.get('check_only', False):
1072 self.SpawnGhost(self.FILE,
1073 payload['sid'],
1074 file_op=('upload', dest_path, payload.get('perm', None)))
1075 self.SendResponse(msg, SUCCESS)
1076
1077 def HandleCreateSymlinkRequest(self, msg):
1078 """Handle create_symlink request."""

Callers 1

HandleRequestMethod · 0.95

Calls 4

SendErrorResponseMethod · 0.95
SpawnGhostMethod · 0.95
SendResponseMethod · 0.95

Tested by

no test coverage detected