Created
June 9, 2017 05:06
-
-
Save cawka/85ac617f1817d9baef0262cd8beebf6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import socket | |
import sys | |
import time | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
if len(sys.argv) != 2: | |
print >>sys.stderr, "ERROR: expected exactly 1 parameter:" | |
print >>sys.stderr, " %s <PORT>" % sys.argv[0] | |
exit(1) | |
sock.bind(("0.0.0.0", int(sys.argv[1]))) | |
sock.listen(1) | |
conn, addr = sock.accept() | |
conn.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 1024) | |
f = open('/tmp/file', 'wb') | |
l = conn.recv(1024) | |
while (l): | |
f.write(l) | |
l = conn.recv(1024) | |
f.close() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment