File Operations
class File
Obtain the subclass for file operations
py
api = mcsm.file()
method show(daemonId: str, uuid: str, target: str = "", page: int = 0, page_size: int = 100, file_name: str = "")
Get the file list
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetarget
: Target path used for file filteringpage
: Page number for paginationpage_size
: Page size for fetching the file listfile_name
: Used to filter files or folders whose names contain the specified string in the file list
Returns
FileList
: Model with detailed file list information
method content(daemonId: str, uuid: str, target: str)
Get file content
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetarget
: Target path of the file
Returns
str
: Content of the file
method update(daemonId: str, uuid: str, target: str, text: str)
Update file content
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetarget
: Path of the target filetext
: New file content
Returns
bool
: Returns True after successful operation
method download(daemonId: str, uuid: str, file_name: str)
Download file
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancefile_name
: Full path within the instance of the file to download, eg: /backup/world.zip
Returns
str
: File download URL
method upload(daemonId: str, uuid: str, file: bytes, upload_dir: str)
TIP
This function is asynchronous
Upload file
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancefile
: Content of the file to uploadupload_dir
: Target path to upload the file to
Returns
bool
: Returns True after successful operation
method copy(daemonId: str, uuid: str, copy_map: dict[str, str])
Copy multiple files or folders to the specified location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancecopy_map
: Copy mapping, format:
Returns
bool
: Returns True after successful operation
method copyOne(daemonId: str, uuid: str, source: str, target: str)
Copy a single file or folder to the specified location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancesource
: Path of the source file or foldertarget
: Path of the target file or folder
Returns
bool
: Returns True after successful operation
method move(daemonId: str, uuid: str, copy_map: dict[str, str])
Move multiple files or folders to the specified location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancecopy_map
: Move mapping, format:
Returns
bool
: Returns True after successful operation
method moveOne(daemonId: str, uuid: str, source: str, target: str)
Move a single file or folder to the specified location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancesource
: Path of the source file or foldertarget
: Path of the target file or folder
Returns
bool
: Returns True after successful operation
method rename(daemonId: str, uuid: str, source: str, new_name: str)
Rename a single file or folder
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancesource
: Path of the source file or foldernew_name
: New name of the source file or folder
Returns
bool
: Returns True after successful operation
method zip(daemonId: str, uuid: str, source: str, targets: list[str])
Compress multiple files or folders to the specified location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancesource
: Target file path to compress totargets
: Paths of the files to compress
Returns
bool
: Returns True after successful operation
method unzip(daemonId: str, uuid: str, source: str, targets: str, code: Literal["utf-8", "gbk", "big5"] = "utf-8")
Unzip the specified zip file to the target location
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancesource
: Path of the zip file to unziptargets
: Target path to unzip tocode
: Encoding of the compressed file
Returns
bool
: Returns True after successful operation
method delete(daemonId: str, uuid: str, targets: list[str])
Delete multiple files or folders
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetargets
: Paths of the files or folders to delete
Returns
bool
: Returns True after successful operation
method createFile(daemonId: str, uuid: str, target: str)
Create a file
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetarget
: Path of the target file, including filename
Returns
bool
: Returns True after successful operation
method createFolder(daemonId: str, uuid: str, target: str)
Create a folder
Parameters
daemonId
: UUID of the nodeuuid
: UUID of the instancetarget
: Path of the target folder
Returns
bool
: Returns True after successful operation