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
1.0 KiB
38 lines
1.0 KiB
1 month ago
|
# @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.29'
|
||
|
port = 8181
|
||
|
#这段代码放在云备份虚拟机上,用于下载
|
||
|
new_name2 = sys.argv[1]#虚拟机上文件夹的地址,以 web/admin/1.txt 为例,这个代码用于下载虚拟机上云备份的文件
|
||
|
l=new_name2.split("/")
|
||
|
username=l[1].encode()#用户名
|
||
|
file=l[2].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()# 关闭连接
|