File Transfer Tools
Transfer files over serial connections using classic X/Y/ZMODEM protocols. These tools work in both RS-232 and RS-485 modes.
Protocol Comparison
Section titled “Protocol Comparison”| Protocol | Block Size | Batch | Resume | Error Correction | Recommended |
|---|---|---|---|---|---|
| XMODEM | 128B | No | No | Checksum/CRC | Legacy only |
| XMODEM-1K | 1024B | No | No | CRC-16 | - |
| YMODEM | 1024B | Yes | No | CRC-16 | Batch needs |
| ZMODEM | Streaming | Yes | Yes | CRC-32 | Yes |
file_transfer_send
Section titled “file_transfer_send”Send a single file over serial using a selected protocol. The receiver must be waiting in receive mode before calling this tool. ZMODEM receivers typically auto-start when they detect the init sequence.
| Parameter | Type | Default | Description |
|---|---|---|---|
port | str | required | Device path of the open serial port. |
file_path | str | required | Path to the file to send. |
protocol | Literal["xmodem", "xmodem1k", "ymodem", "zmodem"] | "zmodem" | Transfer protocol to use. |
Returns: Transfer statistics dict with protocol-specific details including bytes sent and any errors. The dict also includes protocol and file fields.
# Send a firmware file using ZMODEM (default)file_transfer_send(port="/dev/ttyUSB0", file_path="/home/user/firmware.bin")
# Send using XMODEM for legacy compatibilityfile_transfer_send( port="/dev/ttyUSB0", file_path="/home/user/config.txt", protocol="xmodem",)
# XMODEM-1K for faster transfers on legacy systemsfile_transfer_send( port="/dev/ttyUSB0", file_path="/home/user/data.bin", protocol="xmodem1k",)
# YMODEM preserves filename and size metadatafile_transfer_send( port="/dev/ttyUSB0", file_path="/home/user/update.bin", protocol="ymodem",)file_transfer_receive
Section titled “file_transfer_receive”Receive a file over serial using a selected protocol. The behavior of save_path depends on the protocol.
| Parameter | Type | Default | Description |
|---|---|---|---|
port | str | required | Device path of the open serial port. |
save_path | str | required | For XMODEM: full file path. For YMODEM/ZMODEM: directory where received files are saved. |
protocol | Literal["xmodem", "ymodem", "zmodem"] | "zmodem" | Transfer protocol to use. |
overwrite | bool | False | Whether to overwrite existing files. |
Returns: Transfer statistics dict with protocol-specific details including bytes received and file paths. Includes the protocol field.
# Receive via ZMODEM into a directoryfile_transfer_receive( port="/dev/ttyUSB0", save_path="/home/user/downloads/",)
# Receive a single file via XMODEMfile_transfer_receive( port="/dev/ttyUSB0", save_path="/home/user/received_file.bin", protocol="xmodem",)
# Receive via YMODEM, allowing overwritefile_transfer_receive( port="/dev/ttyUSB0", save_path="/home/user/downloads/", protocol="ymodem", overwrite=true,)file_transfer_send_batch
Section titled “file_transfer_send_batch”Send multiple files in a single batch transfer. Only YMODEM and ZMODEM support batch mode.
| Parameter | Type | Default | Description |
|---|---|---|---|
port | str | required | Device path of the open serial port. |
file_paths | list[str] | required | List of file paths to send. |
protocol | Literal["ymodem", "zmodem"] | "zmodem" | Transfer protocol. Must be ymodem or zmodem. |
Returns: Transfer statistics dict covering all files, including the protocol field.
# Batch send with ZMODEM (default)file_transfer_send_batch( port="/dev/ttyUSB0", file_paths=[ "/home/user/config.json", "/home/user/firmware.bin", "/home/user/README.txt", ],)
# Batch send with YMODEMfile_transfer_send_batch( port="/dev/ttyUSB0", file_paths=["/home/user/file1.txt", "/home/user/file2.txt"], protocol="ymodem",)Typical Workflow
Section titled “Typical Workflow”A complete file transfer session looks like this:
# 1. Open the port at a suitable baud rateopen_serial_port(port="/dev/ttyUSB0", baudrate=115200)
# 2. Send a filefile_transfer_send(port="/dev/ttyUSB0", file_path="/home/user/firmware.bin")
# 3. Or receive a filefile_transfer_receive(port="/dev/ttyUSB0", save_path="/home/user/downloads/")
# 4. Close when doneclose_serial_port(port="/dev/ttyUSB0")