使用python xmodem 模組下載及上傳檔案
阿新 • • 發佈:2018-11-26
轉自:https://pypi.org/project/xmodem/
Documentation available at http://packages.python.org/xmodem/
Python Package Index (PyPI) page is available at https://pypi.python.org/pypi/xmodem
Usage
Create a function to get and put character data (to a serial line for example):
>>> import serial >>> from xmodem import XMODEM >>> ser = serial.Serial('/dev/ttyUSB0', timeout=0) # or whatever port you need >>> def getc(size, timeout=1): ... return ser.read(size) or None ... >>> def putc(data, timeout=1): ... return ser.write(data) # note that this ignores the timeout ... >>> modem = XMODEM(getc, putc)
Now, to upload a file, use the send method:
>>> stream = open('/etc/fstab', 'rb') >>> modem.send(stream)
To download a file, use the recv method:
>>> stream = open('output', 'wb') >>> modem.recv(stream)
For more information, take a look at the documentation.