All Projects → sirMackk → py3tftp

sirMackk / py3tftp

Licence: MIT license
An asynchronous TFTP server in pure Python 3.5

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to py3tftp

Aiormq
Pure python AMQP 0.9.1 asynchronous client library
Stars: ✭ 112 (+187.18%)
Mutual labels:  asynchronous, asyncio
Kubernetes asyncio
Python asynchronous client library for Kubernetes http://kubernetes.io/
Stars: ✭ 147 (+276.92%)
Mutual labels:  asynchronous, asyncio
Tornado Sqlalchemy
SQLAlchemy support for Tornado
Stars: ✭ 112 (+187.18%)
Mutual labels:  asynchronous, asyncio
Vibe Core
Repository for the next generation of vibe.d's core package.
Stars: ✭ 56 (+43.59%)
Mutual labels:  asynchronous, asyncio
Aiomisc
aiomisc - miscellaneous utils for asyncio
Stars: ✭ 200 (+412.82%)
Mutual labels:  asynchronous, asyncio
Peony Twitter
An asynchronous Twitter API client for Python 3.5+
Stars: ✭ 62 (+58.97%)
Mutual labels:  asynchronous, asyncio
Purerpc
Asynchronous pure Python gRPC client and server implementation supporting asyncio, uvloop, curio and trio
Stars: ✭ 125 (+220.51%)
Mutual labels:  asynchronous, asyncio
Async Reduce
Reducer for similar simultaneously coroutines
Stars: ✭ 17 (-56.41%)
Mutual labels:  asynchronous, asyncio
Aiosmtplib
asyncio smtplib implementation
Stars: ✭ 200 (+412.82%)
Mutual labels:  asynchronous, asyncio
Paco
Small utility library for coroutine-driven asynchronous generic programming in Python 3.4+
Stars: ✭ 198 (+407.69%)
Mutual labels:  asynchronous, asyncio
Beanie
Micro ODM for MongoDB
Stars: ✭ 56 (+43.59%)
Mutual labels:  asynchronous, asyncio
async retrial
Python package for retrial of asyncio based coroutines
Stars: ✭ 14 (-64.1%)
Mutual labels:  asynchronous, asyncio
Halive
A fast http and https prober, to check which URLs are alive
Stars: ✭ 47 (+20.51%)
Mutual labels:  asynchronous, asyncio
Backoff
Python library providing function decorators for configurable backoff and retry
Stars: ✭ 1,670 (+4182.05%)
Mutual labels:  asynchronous, asyncio
Chili
Chili: HTTP Served Hot
Stars: ✭ 7 (-82.05%)
Mutual labels:  asynchronous, asyncio
Edgedb Python
EdgeDB Python Driver
Stars: ✭ 113 (+189.74%)
Mutual labels:  asynchronous, asyncio
Tornado Celery
Non-blocking Celery client for Tornado
Stars: ✭ 561 (+1338.46%)
Mutual labels:  asynchronous, asyncio
Yappi
Yet Another Python Profiler, but this time thread&coroutine&greenlet aware.
Stars: ✭ 595 (+1425.64%)
Mutual labels:  asynchronous, asyncio
Minotaur
A pythonic, asynchronous, inotify interface
Stars: ✭ 163 (+317.95%)
Mutual labels:  asynchronous, asyncio
socketwrapper
Async/Sync networking library including UDP, TCP and TLS/TCP socket classes written in C++ 17.
Stars: ✭ 33 (-15.38%)
Mutual labels:  asynchronous, asyncio

Py3tftp

Py3tftp is an asynchronous TFTP server written in Python 3. It was written for the pure joy of working with Python 3 and implements RFC 1350 (except mail mode), RFC 2347 (options), RFC 2348 (blksize option), RFC 2349 (timeout, tsize), and RFC 7440 (windowsize) for RRQ. Additionally, it supports block number roll over, so files of any size can be transferred over.

While a toy project, it does adhere to enough of the standards to be useful in real life.

Some Py3k stuff it uses:

This project is in maintenance mode!

It is not actively developed, but it provides a solid minimum set of functionality and works on Python versions 3.5 though 3.9.

If you would like more functionality or if you find a bug, please open a PR :).

Installation

pip install py3tftp

Usage

Invoking pyt3tftp will start a server that will interact with the current working directory - it will read and write files from it so don't run it in a place with sensitive files!

TFTP has no security features, except for its simplicity:

  • It won't overwrite files.
  • Won't create non-existant directories.
  • Cannot write outside of the directory it's running from.
usage: py3tftp [-h] [--host HOST] [-p PORT] [--ack-timeout ACK_TIMEOUT]
                   [--timeout TIMEOUT] [-l FILE_LOG] [-v] [--version]

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           IP of the interface the server will listen on.
                        Default: 0.0.0.0
  -p PORT, --port PORT  Port the server will listen on. Default: 9069. TFTP
                        standard-compliant port: 69 - requires superuser
                        privileges.
  --ack-timeout ACK_TIMEOUT
                        Timeout for each ACK of the lock-step. Default: 0.5.
  --timeout TIMEOUT     Timeout before the server gives up on a transfer and
                        closes the connection. Default: 3.
  -l FILE_LOG, --file-log FILE_LOG
                        Append output to log file.
  -v, --verbose         Enable debug-level logging.
  --version

Testing

I wrote some simple acceptance tests in tests/acceptance/*_test.py. The code is messy as it's meant to be thrown away.

# runs the server with python -m py3tftp
# runs unittests under tests/
# kills the server
./.travis/run.sh

Extending py3tftp

The way that this module works is that there's a subclass of BaseTFTPServerProtocol scheduled on the IO loop that listens for incoming TFTP requests and decides what kind of BaseTFTPProtocol to schedule on the IO loop to handle the incoming request.

The way this works in the default scenario is that TFTPServerProtocol listens to incoming requests. When a request comes in, it selects either the WRQProtocol or the RRQProtocol to create a task in the IO loop and passes the request to the selected protocol upon instantiation. From then on, the instantiated protocol handles all of the communication with the client and the TFTPServerProtocol goes back to listening for requests.

This amazing diagram illustrates the above process in the case of a RRQ request:

py3tftp rrq process diagram

Extending py3tftp is as easy as:

  • Subclassing BaseTFTPServerProtocol, mainly to implement the select_protocol method to select your custom protocol.
  • Subclassing either RRQProtocol or WRQProtocol to implement your own logic (new options, file handling, etc.) for standard WRQ and RRQ requests, OR...
  • Subclassing BaseTFTPProtocol to implement your own logic for a custom type of request.

Roadplan

(Note, this hasn't been updated in a few years)

  • fix off-by-one blksize error ie. if you transfer a file 1000 bytes long and set blksize to 1000 bytes, the server won't ack it.
  • Pull out file reader/writer from protocol classes.
  • Add tsize from RFC 2349 (added by schrd).
  • Add blksize, timeout, and tsize tests.
  • Possibly implement RFCs 906 and 951 for fun!
  • Refactor the code, get rid of some duplication, optimize some low-hanging fruit.

LICENSE

The MIT License (MIT)

Copyright (c) 2016-2021 sirMackk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].