YMODEM written by Python - 用Python实现的YMODEM通讯协议
The YMODEM project is based on XMODEM implementation written by tehmaze. It is also compatible with XMODEM mode.
Interact with SecureCRT as sender
Interact with SecureCRT as Finder
pip install ymodem
# To get help
ymodem -h
# or
python -m ymodem -h
ymodem send ./file.bin ./file2.bin -p COM4 -b 115200
# or
python -m ymodem send ./file.bin ./file2.bin -p COM4 -b 115200
ymodem recv ./ -p COM4 -b 115200
# or
python -m ymodem recv ./ -p COM4 -b 115200
from ymodem.Socket import ModemSocket
# define read
def read(size, timeout = 3):
# implementation
# define write
def write(data, timeout = 3):
# implementation
# create socket
cli = ModemSocket(read, write)
# send multi files
cli.send([file_path1, file_path2, file_path3 ...])
# receive multi files
cli.recv(folder_path)
For more detailed usage, please refer to main.py.
def __init__(self,
read: Callable[[int, Optional[float]], Any],
write: Callable[[Union[bytes, bytearray], Optional[float]], Any],
protocol_type: int = ProtocolType.YMODEM,
protocol_type_options: List[str] = [],
packet_size: int = 1024,
style_id: int = _psm.get_available_styles()[0]):
def send(self,
paths: List[str],
callback: Optional[Callable[[int, str, int, int], None]] = None
) -> bool:
callback: callback function. see below.
Parameter | Description |
---|---|
task index | index of current task |
task (file) name | name of the file |
total packets | number of packets plan to send |
success packets | number of packets successfully sent |
def recv(self,
path: str,
callback: Optional[Callable[[int, str, int, int], None]] = None
) -> bool:
Depending on different communication environments, developers may need to manually adjust timeout parameters in _read_and_wait or _write_and_wait.
If you want to output debugging information, set the log level to DEBUG.
logging.basicConfig(level=logging.DEBUG, format='%(message)s')