USSFiles
- class zos_files.zowe.zos_files_for_zowe_sdk.USSFiles(connection: dict[str, Any], log: bool = True)
Class used to represent the base z/OSMF USSFiles API.
It includes all operations related to USS files.
- Parameters:
connection (dict[str, Any]) – The z/OSMF connection object (generated by the ZoweSDK object)
log (bool) – Flag to disable logger
- create(file_path: str, type: str, mode: str | None = None) None
Add a file or directory.
- Parameters:
file_path (str) – Path of the file to add
type (str) – Specify either “file” or “dir”
mode (Optional[str]) – Unix permission string (e.g. rwxr-xr-x)
- delete(filepath_name: str, recursive: bool = False) None
Delete a file or directory.
- Parameters:
filepath_name (str) – Path of the file to be deleted
recursive (bool) – If specified as True, all the files and sub-directories will be deleted.
- download(file_path: str, output_file: str, binary: bool = False, file_encoding: str = 'IBM-1047', receive_encoding: str = 'UTF-8') None
Use perform_download instead of this deprecated function.
- get_content(filepath_name: str, file_encoding: str = 'IBM-1047', receive_encoding: str = 'ISO8859-1') str | None
Use retrieve_content() instead of this deprecated function.
- get_content_streamed(file_path: str, binary: bool = False, file_encoding: str = 'IBM-1047', receive_encoding: str = 'ISO8859-1') Response
Use retrieve_content(as_stream=True) instead of this deprecated function.
- get_file_tag(filepath_name: str) USSFileTag
Retrieve the file tag if specified for the filename. Raises exception if it is impossible to identify the tag info.
- Parameters:
filepath_name (str) – Path of the file
- Returns:
Tag info of a given file.
- Return type:
USSFileTag
- list(path: str) USSListResponse
Retrieve a list of USS files based on a given pattern.
- Parameters:
path (str) – Path to retrieve the list
- Returns:
A JSON with a list of file names matching the given pattern
- Return type:
USSListResponse
- perform_download(remote_file_path: str, local_file_path: str, content_type: ContentType = ContentType.TEXT, remote_file_encoding: str = 'IBM-1047', receive_in_encoding: str = 'UTF-8') None
Retrieve the contents of a USS file and save it to a local file.
- Parameters:
remote_file_path (str) – Path of the file to be downloaded
local_file_path (str) – Name of the file to be saved locally
content_type (ContentType, optional) – Specifies the content type to fetch (“text” or “binary”, “text” by default)
remote_file_encoding (str, optional) – Encoding file content originally in (to convert from; by default, it is always being converted from “IBM-1047”)
receive_in_encoding (str, optional) – Encoding to convert file content to (to convert to; by default, it is always being converted to “UTF-8” during download). Ignored when “binary” is True
- Raises:
TypeError – Thrown when the retrieve_content request does not return a valid Response object.
ValueError – Content type must be either ContenType.TEXT or ContentType.BINARY.
- perform_upload(local_file_path: str, remote_file_path: str, content_type: ContentType = ContentType.TEXT, upload_in_encoding: str = 'utf-8') None
Upload contents of a given file and save it to a file at the given USS path.
- Parameters:
local_file_path (str) – Name of the file to be uploaded
remote_file_path (str) – Path of the file where it will be created
content_type (ContentType, optional) – Specifies the content type to fetch (“text” or “binary”, “text” by default)
upload_in_encoding (str) – Specifies encoding schema of the uploaded file
- Raises:
FileNotFound – Thrown when specific file is not found.
ValueError – Content type must be either ContenType.TEXT or ContentType.BINARY.
- retrieve_content(file_path: str, content_type: ContentType = ContentType.TEXT, remote_file_encoding: str = 'IBM-1047', receive_in_encoding: str = 'ISO8859-1', as_stream: bool = False) str | None | Response
Retrieve the content of a filename. The complete path must be specified.
- Parameters:
file_path (str) – Path of the file
content_type (ContentType, optional) – The content type to receive (“text” or “binary”, “text” by default)
remote_file_encoding (str, optional) – Encoding file content originally in (to convert from; by default, it is always being converted from “IBM-1047”)
receive_in_encoding (str, optional) – Encoding to convert file content to (to convert to; by default, it is always being converted to “ISO8859-1”)
as_stream (bool, optional) – Specifies whether the response is streamed. Default: False
- Returns:
Contents of a given USS file in string, or None if the file is empty, or a Response object with content of the file if as_stream == True
- Return type:
Union[str, None, Response]
- Raises:
ValueError – Content type must be either ContenType.TEXT or ContentType.BINARY.
- upload(input_file: str, filepath_name: str, encoding: str = 'utf-8', binary: bool = False) None
Use perform_upload() instead of this deprecated function.
- write(filepath_name: str, data: str | bytes, encoding: str = 'utf-8') None
Write content to a UNIX file or create it with the content if it does not exist.
- Parameters:
filepath_name (str) – Path of the file
data (Union[str, bytes]) – Contents to be written
encoding (str) – Specifies the encoding name (e.g. IBM-1047)
- Raises:
ValueError – Data must be either a string or bytes.