代码拉取完成,页面将自动刷新
同步操作将从 现任明教教主-乾颐堂/qytang_Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import sys, os, time, _thread as thread
from socket import *
blksz = 100
defaultHost = 'localhost'
defaultPort = 50001
helptext = """
Usage...
server => getfile.py -mode server [-port nnn] [-host hhh] [localhost]
client => getfile.py -mode client -file fff [-port nnn] [-host hhh] [localhost]
"""
def now():
return time.asctime()
def parsecommandline():
dict = {}
args = sys.argv[1:]
while len(args) >= 2:
dict[args[0]] = args[1]
args = args[2:]
return dict
def client(host, port, filename):
print(filename)
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((host, port))
sock.send((filename + '\n').encode())
dropdir = os.path.split(filename)[1]
print(dropdir)
file = open(dropdir, 'wb')
while True:
data = sock.recv(blksz)
if not data: break
file.write(data)
sock.close()
file.close()
print('Client got', filename, 'at', now())
def serverthread(clientsock):
sockfile = clientsock.makefile('r')
filename = sockfile.readline()[:-1]
print(filename)
file = open(filename, 'rb')
try:
while True:
bytes = file.read(blksz)
if not bytes: break
sent = clientsock.send(bytes)
assert sent == len(bytes)
except:
print('Error downloading file on server:', filename)
clientsock.close()
def server(host, port):
serversock = socket(AF_INET, SOCK_STREAM)
serversock.bind((host, port))
serversock.listen(5)
while True:
clientsock, clientaddr = serversock.accept()
print('Server connected by', clientaddr, 'at', now())
thread.start_new_thread(serverthread, (clientsock,))
def main(args):
host = args.get('-host', defaultHost)
port = int(args.get('-port', defaultPort))
if args.get('-mode') == 'server':
if host == 'localhost': host = ''
server(host, port)
elif args.get('-file'):
client(host, port, args['-file'])
else: print(helptext)
if __name__ == '__main__':
args = parsecommandline()
main(args)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。