Skip to content

drmats/pyfup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyfup

Basic file upload WSGI application (python 2.6.x/2.7.x/3.3.x)

This script brings up a simple_server from python's wsgiref package and runs a really simple WSGI (PEP 3333) application on it. It allows to upload any file using multipart/form-data form content type. When Document Object Model Events, Selectors API, File API, XMLHttpRequest, XMLHttpRequestUpload and FormData are available on the client side then upload process is performed with the usage of client-side logic, allowing user to see the progress. Otherwise simple POST request from within HTML form is performed.

pyfup doesn't depend on any external library - just vanilla python environment is required.

Don't use it in production environment as it has not been reviewed for security issues, however it's handy for ad-hoc file transfers between machines over HTTP protocol.

GitHub top language GitHub code size GitHub tag

$ python3 fup.py
[WSGIServer/0.2 CPython/3.6.5 pyfup/0.5.5]
listening on 0.0.0.0:8000 <192.168.1.13:8000>

installation

No installation is necessary. Just download the latest version.


usage

  • standalone:

    $ python fup.py --help
    usage: fup.py [-h] [-v] [--ssl] [-k KEY] [-c CERT] [-a AUTH] [--no-js]
                    [--use-sproxy] [--host HOST]
                    [port]
    
    Basic file upload WSGI application.
    
    positional arguments:
        port                  specify alternate port [default: 8000]
    
    optional arguments:
        -h, --help            show this help message and exit
        -v, --version         show program's version number and exit
        --ssl                 use SSL
        -k KEY, --key KEY     path to SSL key file
        -c CERT, --cert CERT  path to SSL certificate file
        -a AUTH, --auth AUTH  specify username:password that will be required from
                            user agent [default: no authentication required]
        --no-js               do not use JavaScript on client side
        --use-sproxy          use "sniffing" proxy for autodetect and switch to SSL
                            (EXPERIMENTAL FEATURE)
        --host HOST           specify host [default: 0.0.0.0]
    
    More at: https://github.com/drmats/pyfup
    
  • with werkzeug:

    $ python -m werkzeug.serving [-b HOST:PORT] fup:app
    
  • with gunicorn:

    $ gunicorn [-b HOST] --access-logfile - fup:app
    
  • in order to be able to accept big files and avoid "worker timeouts" it is desirable to use asynchronous (eventlet or tornado) worker classes:

    $ gunicorn [-b HOST] -k eventlet --access-logfile - fup:app
    $ gunicorn [-b HOST] -k gevent --access-logfile - fup:app
    $ gunicorn [-b HOST] -k tornado fup:app
    
  • with Twisted Web:

    $ twistd -n web [--port PORT] --wsgi fup.app
    
  • with uWSGI:

    $ uwsgi --plugin python --http :[PORT] --wsgi-file fup.py --callable app
    
  • with waitress:

    $ waitress-serve --port [PORT] fup:app
    

notes on SSL

The easiest way to generate private key and self-signed certificate with OpenSSL:

$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 -keyout ssl.key -out ssl.cert

Beware that browser will complain that it can't confirm site's identity and on first connection pyfup can log a request error "SSLV3_ALERT_CERTIFICATE_UNKNOWN" (this behavior is user-agent dependent).


support

You can support this project via stellar network:


license

pyfup is released under the BSD 2-Clause license. See the LICENSE for more details.


notes

The script was tested and is known to work with python versions 2.7.2, 2.7.3, 2.7.5, 3.3.0, 3.3.2 and 3.3.3 on linux and windows, but theoretically it should work on all 2.6.x, 2.7.x and 3.3.x.