You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
988 B
38 lines
988 B
# @Coding: utf-8
|
|
# @Time: 2022/4/25 3:45 下午
|
|
from fileinput import filename
|
|
import socket
|
|
import sys
|
|
import argparse
|
|
import os
|
|
from importlib.resources import contents
|
|
host = '192.168.43.114'
|
|
port = 8181
|
|
|
|
new_name2 = sys.argv[1]#上传到本地文件夹的地址,以 ./public/users/admin/download_server.py为例
|
|
l=new_name2.split("/")
|
|
username=l[2].encode()#用户名
|
|
file=l[3].encode()#文件名
|
|
|
|
|
|
so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
f=open(new_name2,'rb')
|
|
content=f.read()
|
|
size = str(os.stat(new_name2).st_size).encode() # 获取文件大小
|
|
print("size:",size)
|
|
f.close()
|
|
so.connect((host, port))# 连接服务器端
|
|
data = so.recv(1024)# 接收数据
|
|
print(f"get message: {data}")
|
|
so.send(b'user '+username+b" ")# 发送用户名
|
|
so.recv(1024)
|
|
print("s1")
|
|
so.send(b'file '+file+b" ")# 发送文件名
|
|
so.recv(1024)
|
|
print("s2")
|
|
so.send(b'size '+size+b" ")# 发送文件名
|
|
so.recv(1024)
|
|
print('s3')
|
|
so.send(content)# 发送文件内容
|
|
so.close()# 关闭连接
|