Skip to content

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.

ProtocolBlock SizeBatchResumeError CorrectionRecommended
XMODEM128BNoNoChecksum/CRCLegacy only
XMODEM-1K1024BNoNoCRC-16-
YMODEM1024BYesNoCRC-16Batch needs
ZMODEMStreamingYesYesCRC-32Yes

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.

ParameterTypeDefaultDescription
portstrrequiredDevice path of the open serial port.
file_pathstrrequiredPath to the file to send.
protocolLiteral["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 compatibility
file_transfer_send(
port="/dev/ttyUSB0",
file_path="/home/user/config.txt",
protocol="xmodem",
)
# XMODEM-1K for faster transfers on legacy systems
file_transfer_send(
port="/dev/ttyUSB0",
file_path="/home/user/data.bin",
protocol="xmodem1k",
)
# YMODEM preserves filename and size metadata
file_transfer_send(
port="/dev/ttyUSB0",
file_path="/home/user/update.bin",
protocol="ymodem",
)

Receive a file over serial using a selected protocol. The behavior of save_path depends on the protocol.

ParameterTypeDefaultDescription
portstrrequiredDevice path of the open serial port.
save_pathstrrequiredFor XMODEM: full file path. For YMODEM/ZMODEM: directory where received files are saved.
protocolLiteral["xmodem", "ymodem", "zmodem"]"zmodem"Transfer protocol to use.
overwriteboolFalseWhether 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 directory
file_transfer_receive(
port="/dev/ttyUSB0",
save_path="/home/user/downloads/",
)
# Receive a single file via XMODEM
file_transfer_receive(
port="/dev/ttyUSB0",
save_path="/home/user/received_file.bin",
protocol="xmodem",
)
# Receive via YMODEM, allowing overwrite
file_transfer_receive(
port="/dev/ttyUSB0",
save_path="/home/user/downloads/",
protocol="ymodem",
overwrite=true,
)

Send multiple files in a single batch transfer. Only YMODEM and ZMODEM support batch mode.

ParameterTypeDefaultDescription
portstrrequiredDevice path of the open serial port.
file_pathslist[str]requiredList of file paths to send.
protocolLiteral["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 YMODEM
file_transfer_send_batch(
port="/dev/ttyUSB0",
file_paths=["/home/user/file1.txt", "/home/user/file2.txt"],
protocol="ymodem",
)

A complete file transfer session looks like this:

# 1. Open the port at a suitable baud rate
open_serial_port(port="/dev/ttyUSB0", baudrate=115200)
# 2. Send a file
file_transfer_send(port="/dev/ttyUSB0", file_path="/home/user/firmware.bin")
# 3. Or receive a file
file_transfer_receive(port="/dev/ttyUSB0", save_path="/home/user/downloads/")
# 4. Close when done
close_serial_port(port="/dev/ttyUSB0")