Exemplo n.º 1
0
def server_method(con,mask):
    cmd = con.recv(1024)
    if not cmd:
        sel.unregister(con)
        con.close()
    else:
        data = cmd.decode()
        res = data.split("+")
        name = res[1]
        pswd = res[2]
        if res[0] == "login":
            server_show("The request to receive the client landing is landing....", "msg")
            user = User(name, pswd)
            sign = user.login()
            if sign:
                con.sendall(bytes("Success", encoding="utf-8"))
            else:
                con.sendall(bytes("Failure", encoding="utf-8"))
        if res[0] == "register":
            server_show("The request to receive the client register is register....", "msg")
            user = User(name, pswd)
            if user.register():
                con.sendall(bytes("Success", encoding="utf-8"))
            else:
                con.sendall(bytes("Failure", encoding="utf-8"))
        if res[0] == "view":
            server_show("Request to view the list of files under the directory....", "msg")
            user = User(name, pswd)
            if user.view_file():
                con.sendall(bytes("Success", encoding="utf-8"))
            else:
                con.sendall(bytes("Failure", encoding="utf-8"))
        if res[0] == "upload":
            server_show("receiving a request from a client to upload a file....","msg")
            con.send(bytes("True", encoding="utf-8"))
        if res[0] == "uploadfile":
            res_length = res[3]
            filename = res[4]
            User.receive(filename, name, res_length, con)
        if res[0] == "download":
            server_show("receiving a request from a client to download a file....","msg")
            user = User(name, pswd)
            res = str(user.view_file())
            con.sendall(bytes(res, encoding="utf-8"))
        if res[0] == "downloadfile":
            filename = res[3]
            User.download_file(filename, name, con)
            server_show("file download success....", "info")
Exemplo n.º 2
0
 def download(self, res):
     server_show(
         "Receive the request from the client to download the file....",
         "msg")
     name = res[1]
     psd = res[2]
     user = User(name, psd)
     dirs, files = user.view_file()
     file = str(files)
     self.request.sendall(bytes(file, encoding="utf-8"))
     res = self.request.recv(1024).decode()
     if User.download_file(res, name, self.request):
         server_show("The file download success....", "info")
     else:
         server_show("The file download failure....", "error")
Exemplo n.º 3
0
 def view(self, res):
     server_show(
         "Receives the client's request to view the current directory file...",
         "msg")
     name = res[1]
     psd = res[2]
     user = User(name, psd)
     dirs, files = user.view_file()
     dir = str(dirs)
     file = str(files)
     if len(dirs) == 0:
         self.request.sendall("False".encode("utf-8"))
     else:
         self.request.sendall(bytes(dir, encoding="utf-8"))
     self.request.sendall(bytes(file, encoding="utf-8"))
     self.request.recv(1024)
     dic = User.info_read(name)
     storage = str(dic["storage"])
     self.request.sendall(bytes(storage, encoding="utf-8"))
     server_show("Current directory file view success...", "info")