Skip to content

4.9 File Manager

Overview

FileManager is used to upload, download, delete, or search resources such as robot programs, trajectories, and temporary files between the host computer and the robot controller. Through the file_manager interface you can batch-manage files of types like USER_PROGRAM, BLOCK_PROGRAM, TRAJECTORY, and ROBOT_TMP, with support for overwrite control and pattern-matching queries—making it easy to deploy/back up programs or synchronize debug data from the production line.

4.9.1 Upload a Local File to the Robot

Method Namefile_manager.upload( file_path : str, file_type : str, overwriting : bool = False) -> StatusCodeEnum
DescriptionUploads a local file to the robot controller.
Request Parametersfile_path : str Absolute path to the local file.
file_type : str File type:
USER_PROGRAM : file_path should point to the program base name (e.g., /root/robot_data/test_prog ); uploads test_prog.json and test_prog.xml from the same directory.
BLOCK_PROGRAM : file_path should point to the block program base name (e.g., /root/robot_data/test_block_prog ); uploads test_block_prog.block , test_block_prog.json , and test_block_prog.xml .
TRAJECTORY : file_path should be the full path to a .trajectory file (e.g., /root/robot_data/test_torque.trajectory ).
ROBOT_TMP : file_path should be the full path to the temporary file (e.g., /root/robot_data/test.csv ).
overwriting : bool Whether to overwrite an existing file on the robot. Default: False .
Return ValueStatusCodeEnum: Result of the function execution.
Compatible robot software versionCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+
NoteFor USER_PROGRAM and BLOCK_PROGRAM , specify only the base name (no suffix).

4.9.2 Download a Robot File to Local

Method Namefile_manager.download( file_name : str, file_path : str, file_type : str, overwriting : bool=False) -> StatusCodeEnum
DescriptionDownloads a file from the robot to a local directory.
Request Parametersfile_name : str File name. Requirements by type:
USER_PROGRAM : provide the program base name (no suffix); downloads both .json and .xml .
TRAJECTORY : provide the full file name including the .trajectory suffix.
ROBOT_TMP : provide the full file name including suffix (e.g., .csv ).
file_path : str Local save directory.
file_type : str File type ( BLOCK_PROGRAM is not supported for download).
overwriting : bool Whether to overwrite an existing file with the same name in the target path.
Return ValueStatusCodeEnum: Result of the function execution.
Compatible robot software versionCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

4.9.3 Delete a File on the Robot

Method Namefile_manager.delete( file_name : str, file_type : str) -> StatusCodeEnum
DescriptionDeletes a file from the robot controller.
Request Parametersfile_name : str File name to delete. Requirements by type:
USER_PROGRAM / BLOCK_PROGRAM : provide the program base name (no suffix).
TRAJECTORY / ROBOT_TMP : provide the full file name including suffix.
file_type : str File type.
Return ValueStatusCodeEnum: Result of the function execution.
Compatible robot software versionCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

4.9.4 Search for Files Matching a Pattern

Method Namefile_manager.search( pattern : str, file_list : list) -> StatusCodeEnum
DescriptionSearches for files on the controller that match the specified pattern.
Request Parameterspattern : str Filename match pattern.
file_list : list Output list to receive matching file names.
Return ValueStatusCodeEnum: Result of the function execution.
Compatible robot software versionCollaborative (Copper): v7.5.0.0+
Industrial (Bronze): v7.5.0.0+

Example Code

file_manager/file_manager.py
py
#!python
"""
Copyright © 2016 Agilebot Robotics Ltd. All rights reserved.
Instruction: 文件操作, 上传下载示例 / Example of file operation, upload and download
"""

from pathlib import Path

from Agilebot import ROBOT_TMP, TRAJECTORY, USER_PROGRAM, FileManager, StatusCodeEnum

current_path = Path(__file__)
path = str(current_path)

# [ZH] 连接文件管理服务
# [EN] Connect to the file management service
file_manager = FileManager("10.27.1.254")

# [ZH] 上传其他文件
# [EN] Upload other files
tmp_file_path = path.replace("file_manager.py", "test.csv")
ret = file_manager.upload(tmp_file_path, ROBOT_TMP, True)
if ret == StatusCodeEnum.OK:
    print("文件上传成功 / File upload successful")
else:
    print(f"文件上传失败,错误代码 / File upload failed, error code: {ret.errmsg}")
    exit(1)

# [ZH] 上传程序
# [EN] Upload a program
prog_file_path = path.replace("file_manager.py", "test_prog")
ret = file_manager.upload(prog_file_path, USER_PROGRAM, True)
if ret == StatusCodeEnum.OK:
    print("程序上传成功 / Program upload successful")
else:
    print(f"程序上传失败,错误代码 / Program upload failed, error code: {ret.errmsg}")
    exit(1)

# [ZH] 上传轨迹
# [EN] Upload a trajectory
trajectory_file_path = path.replace("file_manager.py", "test_torque.trajectory")
ret = file_manager.upload(trajectory_file_path, TRAJECTORY, True)
if ret == StatusCodeEnum.OK:
    print("轨迹上传成功 / Trajectory upload successful")
else:
    print(f"轨迹上传失败,错误代码 / Trajectory upload failed, error code: {ret.errmsg}")
    exit(1)

# [ZH] 搜索文件
# [EN] Search for files
file_list = list()
ret = file_manager.search("test.csv", file_list)
if ret == StatusCodeEnum.OK:
    print("文件搜索成功 / File search successful")
else:
    print(f"文件搜索失败,错误代码 / File search failed, error code: {ret.errmsg}")
    exit(1)
print("搜索文件:", file_list)

# [ZH] 下载文件
# [EN] Download a file
download_file_path = path.replace("file_manager.py", "download")
ret = file_manager.download("test_torque", download_file_path, file_type=TRAJECTORY)
if ret == StatusCodeEnum.OK:
    print("文件下载成功 / File download successful")
else:
    print(f"文件下载失败,错误代码 / File download failed, error code: {ret.errmsg}")
    exit(1)

# [ZH] 删除文件
# [EN] Delete a file
ret = file_manager.delete("test_torque.trajectory", TRAJECTORY)
if ret == StatusCodeEnum.OK:
    print("文件删除成功 / File delete successful")
else:
    print(f"文件删除失败,错误代码 / File delete failed, error code: {ret.errmsg}")
    exit(1)