下列代码实现在客户端上传、下载和浏览服务器文件
运行环境:ubuntu16.04、python3.5
服务端IP:192.168.1.8 开放端口号:4518
服务端代码:
###################################################################
#*- -*#
#*- coding : UTF-8 -*#
#*- function : servicer -*#
#*- localhost : 192.168.1.8 -*#
#*- port : 4518 -*#
#*- author : pwn_w -*#
#*- -*#
###################################################################
import socket,time,socketserver,struct,os
host='192.168.1.8' #本机IP地址
port=4518 #使用的端口
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) #定义socket类型
s.bind((host,port)) #绑定需要监听的Ip和端口号,tuple格式
s.listen(1)
#--------------------------------接收文件---------------------------------#
def receiverFile(connection,address):
try:
filename = str(conn.recv(1024),encoding="utf8")
print('Get filename',filename)
conn.sendall(bytes(filename,encoding="utf8"))
connection.settimeout(600)
fileinfo_size=s