ファイルのアップロードに使えるミニウェブサーバ
Debian pkgが存在する(jessie以降)ので導入もお手軽.UbuntuはXenial(16.04)以降. RaspberryPi OS armhf(buster) にもpkgあり.
ちなみにw3mでも利用可能.
$ sudo apt install droopy
$ droopy -h _____ | \.----.-----.-----.-----.--.--. | -- | _| _ | _ | _ | | | |_____/|__| |_____|_____| __|___ | |__| |_____| usage: droopy [-h] [-d DIRECTORY] [-m MESSAGE] [-p PICTURE] [--publish-files] [-a AUTH] [--ssl SSL] [--chmod CHMOD] [--save-config] [--delete-config] [--config-file CONFIG_FILE] [port] Usage: droopy [options] [PORT] positional arguments: port port number to host droopy upon optional arguments: -h, --help show this help message and exit -d DIRECTORY, --directory DIRECTORY set the directory to upload files to -m MESSAGE, --message MESSAGE set the message -p PICTURE, --picture PICTURE set the picture --publish-files, --dl provide download links -a AUTH, --auth AUTH set the authentication credentials, in form USER:PASS --ssl SSL set up https using the certificate file --chmod CHMOD set the file permissions (octal value) --save-config save options in a configuration file --delete-config delete the configuration file and exit --config-file CONFIG_FILE configuration file to load terminal arguments from. Example: droopy -m "Hi, this is Bob. You can send me a file." -p avatar.png
$ droopy _____ | \.----.-----.-----.-----.--.--. | -- | _| _ | _ | _ | | | |_____/|__| |_____|_____| __|___ | |__| |_____| No configuration file found Files will be uploaded to /home/matoken/Documents HTTP server starting... Check it out at http://localhost:8000
http://localhost:8000 にアクセスするとアップロードページが表示される.ポート変更も可能. ※同じネットワークからも見える.
$ droopy -d ~/tmp/upload/ -m 'hello droopy' -p ~/tmp/upload/13-3733667.jpg --publish-files --chmod 400
-d, --directory
アップロードディレクトリ指定(既定値はカレントディレクトリ)-m, --message
メッセージ-p, --picture
バナー画像--publish-files, --dl
アップロードディレクトリのファイルをダウンロードできるようリンクを表示する.※このオプションを付けなくてもファイル名がわかっていればダウンロードできてしまう.--chmod
8進数で指定したパーミッションになるメモリ利用量の目安
$ ps -eo rss,pid,args | egrep -i droopy | grep -v grep 19180 4126876 /usr/bin/python3 /usr/bin/droopy -d /tmp/upload -m hello droopy. -p /tmp/upload/20201224_18:12:13-3733667.jpg --chmod 400 $ ps -eo rss,pid,args | egrep -i droopy | grep -v egrep | awk '{sum += $1} END {print sum}' 22040
ngrokでhttps公開する例
$ ngrok http localhost:8000 --region jp --log stdout --bind-tls true
同名のファイルガップロードされたときの動き
hoge.jpg
が既に存在する状態で同名のファイルをアップロードした場合,hoge.jpg
は保持され,新たにアップロードされたファイルは hoge-1.jpg
となった
debian packege版で -a, --auth
で認証をかけようとするとこのようなエラーメッセージが表示されてdroopyが利用できない
Exception occurred during processing of request from ('127.0.0.1', 35512) Traceback (most recent call last): File "/usr/lib/python3.9/socketserver.py", line 650, in process_request_thread self.finish_request(request, client_address) File "/usr/lib/python3.9/socketserver.py", line 360, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python3.9/socketserver.py", line 720, in __init__ self.handle() File "/usr/bin/droopy", line 397, in handle httpserver.BaseHTTPRequestHandler.handle(self) File "/usr/lib/python3.9/http/server.py", line 427, in handle self.handle_one_request() File "/usr/lib/python3.9/http/server.py", line 415, in handle_one_request method() File "/usr/bin/droopy", line 122, in decorated expected = 'Basic ' + base64.b64encode(self.auth) File "/usr/lib/python3.9/base64.py", line 58, in b64encode encoded = binascii.b2a_base64(s, newline=False) TypeError: a bytes-like object is required, not 'str'
修正済のよう
この修正で動作するのを確認.
$ wget https://raw.githubusercontent.com/hdf/Droopy/3ac476fe4a703c1df99aa5208e1646468ee6aa65/droopy $ python3 ./droopy -a user:pass
reportbugした
コメント