Skip to content

File Operation Related Models

class FileType(IntEnum)

File type enumeration

Enum ItemEnum ValueDescription
FOLDER0Folder
FILE1File

class FileItem(BaseModel)

File information

FieldTypeDescription
namestrFile or folder name
sizeintFile size (unit: bytes)
timestrFile modification time
modeintFile operation permissions (Linux only)
typeFileTypeFile type
daemonIdstrRemote node UUID
uuidstrInstance UUID
targetstrPath where the file is located
file_namestrFilter condition for current file list

method rename(self, new_name: str)

Rename this file or folder

Parameters

  • new_name: New name for the source file or folder

Returns

  • bool: Returns True after successful operation

method delete(self)

Delete this file or folder

Returns

  • bool: Returns True after successful operation

method copy2(self, target: str)

Copy this file or folder to the target path

Parameters

  • target: Target path

Returns

  • bool: Returns True after successful operation

method move(self, target: str)

Move this file or folder to the target path

Parameters

  • target: Target path

Returns

  • bool: Returns True after successful operation

method content(self)

Get the file content

Returns

  • str: File content

method zip(self, targets: list[str])

Compress this file or folder to the specified location

Parameters

  • targets: Target file path to compress to

Returns

  • bool: Returns True after successful operation

method unzip(self, target: str, code: Literal["utf-8", "gbk", "big5"] = "utf-8")

Unzip this zip file to the specified location

Parameters

  • target: Target path to unzip to
  • code: Encoding of the compressed file

Returns

  • bool: Returns True after successful operation

method update(self, text: str)

Update the file content

Parameters

  • text: File content

Returns

  • bool: Returns True after successful operation

method download(self)

Download this file

Returns

  • str: File download URL

class FileList(BaseModel)

File list

FieldTypeDescription
itemslist[FileItem]List of file information
pageintCurrent page number
pageSizeintNumber of items per page in the file list
totalintTotal number of pages
absolutePathstrAbsolute path of the current directory on the remote node
daemonIdstrRemote node UUID
uuidstrInstance UUID
targetstrPath of the file (name or directory)

method upload(self, file: bytes, upload_dir: str)

TIP

This function is asynchronous

Upload a file to the instance

Parameters

  • file: Content of the file to upload
  • upload_dir: Target path to upload the file to

Returns

  • bool: Returns True if the operation is successful

method createFile(self, target: str)

Create a file

Parameters

  • target: Path of the target file, including the filename

Returns

  • bool: Returns True after successful operation

method createFolder(self, target: str)

Create a folder

Parameters

  • target: Path of the target folder

Returns

  • bool: Returns True after successful operation

class FileDownloadConfig(BaseModel)

File download configuration

FieldTypeDescription
passwordstrPassword for file download
addrstrFile download address

Released under the MIT License.