Skip to content

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 node
  • uuid: UUID of the instance
  • target: Target path used for file filtering
  • page: Page number for pagination
  • page_size: Page size for fetching the file list
  • file_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 node
  • uuid: UUID of the instance
  • target: 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 node
  • uuid: UUID of the instance
  • target: Path of the target file
  • text: 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 node
  • uuid: UUID of the instance
  • file_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 node
  • uuid: UUID of the instance
  • file: Content of the file to upload
  • upload_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 node
  • uuid: UUID of the instance
  • copy_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 node
  • uuid: UUID of the instance
  • source: Path of the source file or folder
  • target: 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 node
  • uuid: UUID of the instance
  • copy_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 node
  • uuid: UUID of the instance
  • source: Path of the source file or folder
  • target: 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 node
  • uuid: UUID of the instance
  • source: Path of the source file or folder
  • new_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 node
  • uuid: UUID of the instance
  • source: Target file path to compress to
  • targets: 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 node
  • uuid: UUID of the instance
  • source: Path of the zip file to unzip
  • targets: Target path to unzip to
  • code: 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 node
  • uuid: UUID of the instance
  • targets: 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 node
  • uuid: UUID of the instance
  • target: 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 node
  • uuid: UUID of the instance
  • target: Path of the target folder

Returns

  • bool: Returns True after successful operation

Released under the MIT License.