Exemple #1
0
 def __init__(self):
     """
     sets the folder_manger value to be no - so that on startup it will go on
     """
     self.reg = ReadRegistry()
     self.reg.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                           FOLDER_MANAGER_REG, NO_REG)
Exemple #2
0
 def __init__(self):
     self.reg = ReadRegistry(CLIENT_REG)
     self.username = self.reg.read_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                            USERNAME_REG)
     self.password = self.reg.read_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                            PASSWORD_REG)
     self.client = Client(CLIENT_MODE, None, None)
     if self.username == BLANK and self.password == BLANK:
         app = wx.App()
         RegisterGUI(self.client)
         app.MainLoop()
     else:
         app = wx.App()
         SystemRegisterGUI(LOG_IN_BTN, self.client)
         app.MainLoop()
Exemple #3
0
    def __init__(self):
        """
        :param request: the request of the file to receive from server
        """
        # initiates request (clicked file path)
        self.request = Application.get_request()
        self.client_reg = ReadRegistry(CLIENT_REG)
        self.server_key = OpenKey(HKEY_LOCAL_MACHINE, SERVER_REG,
                                  REGISTRY_ZERO, KEY_READ)
        self.client_key = OpenKey(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                  REGISTRY_ZERO, KEY_READ)

        ip, port = self.get_ip_port()
        self.ip = ip
        self.port = port
        self.cloud = Application.read_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                               CLOUD_REG)
        self.temp = self.cloud + APPINFO
        self.username = Application.read_registry(HKEY_LOCAL_MACHINE,
                                                  CLIENT_REG, USERNAME_REG)

        # initiates socket
        try:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.ip, self.port))
            # sends the request to the server
            path_to_send = self.without_cloud(self.request)
            Application.send_request_to_server(
                self.sock, self.username + SEPERATOR + DOWNLOAD_FILE +
                SEPERATOR + path_to_send)
            format = Application.read_server_response(self.sock).decode()
            if format != ERROR_FORMAT:
                self.path_file = self.download(format)
                self.start_file_and_wait()
                folder_comp = self.request.split("\\")
                fine_folder_comp = folder_comp[:END]
                folder = "\\".join(fine_folder_comp)
                # self.copy_file(self.path_file, folder)  # so we don't trigger watchdog
                self.upload()
                # src_path = sys.argv[SECOND]
                # new_file = src_path.split(".")[START] + "." + format
                # Application.delete_file(new_file)

            self.sock.close()
        except Exception as msg:
            print("connection error:", msg)
Exemple #4
0
 def __init__(self, ip, port):
     """
     initiates the server
     :param ip: ip
     :param port: port
     """
     try:
         self.sock_dict = {}  # holds the online users
         self.ip = ip
         self.port = port
         reg = ReadRegistry(SERVER_REG)  # server reading
         self.cloud = reg.get_cloud()
         self.server_socket = self.initiate_server_socket()
         self.clients = START_COUNT
         self.lock = threading.Lock()
     except socket.error as msg:
         print("Connection failure: %s\n terminating program" % msg)
Exemple #5
0
 def __init__(self, constructor_mode, ip, port):
     """
     :param constructor_mode: 0- Known username (application & log in)
                              1- Unknown username (set up)
                              2 - Known Username + request socket (mid gui mode)
     :param ip: optional
     :param port: optional
     :param request: optional
     """
     try:
         # initiate socket
         self.user_pc = getpass.getuser()
         self.project_files = PATH_TO_PROJECT_FILES % self.user_pc
         if constructor_mode == CLIENT_MODE:
             reg = ReadRegistry(SERVER_REG)  # server cloud
             ip1, port1 = reg.get_ip_port()
             if ip is not None and port is not None:
                 self.ip = ip
                 self.port = port
             else:
                 self.ip = ip1
                 self.port = port1
             self.request = NO_COMMAND
             self.req_socket = socket.socket(socket.AF_INET,
                                             socket.SOCK_STREAM)
             self.req_socket.connect((self.ip, self.port))
             self.my_socket = socket.socket(socket.AF_INET,
                                            socket.SOCK_STREAM)
             # connect to server
             self.my_socket.connect((self.ip, self.port))
             self.username = NO_USER
             self.password = NO_PASSWORD
             self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
             self.cloud = self.client_reg. \
                 read_registry(HKEY_LOCAL_MACHINE,
                               CLIENT_REG, CLOUD_REG)
         elif constructor_mode == APP_MODE:
             self.request = NO_COMMAND
             reg_ip = ReadRegistry(SERVER_REG)  # client reading
             self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
             self.client_reg.set_observer(ALLOW_OBS)  # initiates
             ip1, port1 = reg_ip.get_ip_port()
             if ip is not None and port is not None:
                 self.ip = ip
                 self.port = port
             else:
                 self.ip = ip1
                 self.port = port1
             self.username = self.client_reg. \
                 read_registry(HKEY_LOCAL_MACHINE,
                               CLIENT_REG, USERNAME_REG)
             self.password = self.client_reg. \
                 read_registry(HKEY_LOCAL_MACHINE,
                               CLIENT_REG, PASSWORD_REG)
             self.cloud = self.client_reg. \
                 read_registry(HKEY_LOCAL_MACHINE,
                               CLIENT_REG, CLOUD_REG)
             self.my_socket = socket.socket(socket.AF_INET,
                                            socket.SOCK_STREAM)
             # connect to server
             self.my_socket.connect((self.ip, self.port))
         elif constructor_mode == MID_GUI_MODE:
             reg = ReadRegistry(SERVER_REG)  # server cloud
             ip1, port1 = reg.get_ip_port()
             if ip is not None and port is not None:
                 self.ip = ip
                 self.port = port
             else:
                 self.ip = ip1
                 self.port = port1
             self.request = NO_COMMAND
             self.req_socket = socket.socket(socket.AF_INET,
                                             socket.SOCK_STREAM)
             self.req_socket.connect((self.ip, self.port))
             self.my_socket = socket.socket(socket.AF_INET,
                                            socket.SOCK_STREAM)
             # connect to server
             self.my_socket.connect((self.ip, self.port))
             self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
             self.username = self.client_reg.read_registry(
                 HKEY_LOCAL_MACHINE, CLIENT_REG, USERNAME_REG)
             self.password = self.client_reg.read_registry(
                 HKEY_LOCAL_MACHINE, CLIENT_REG, PASSWORD_REG)
             self.cloud = self.client_reg. \
                 read_registry(HKEY_LOCAL_MACHINE,
                               CLIENT_REG, CLOUD_REG)
     except Exception as msg:
         print("at constructor Client", msg)
Exemple #6
0
class Client(object):
    def __init__(self, constructor_mode, ip, port):
        """
        :param constructor_mode: 0- Known username (application & log in)
                                 1- Unknown username (set up)
                                 2 - Known Username + request socket (mid gui mode)
        :param ip: optional
        :param port: optional
        :param request: optional
        """
        try:
            # initiate socket
            self.user_pc = getpass.getuser()
            self.project_files = PATH_TO_PROJECT_FILES % self.user_pc
            if constructor_mode == CLIENT_MODE:
                reg = ReadRegistry(SERVER_REG)  # server cloud
                ip1, port1 = reg.get_ip_port()
                if ip is not None and port is not None:
                    self.ip = ip
                    self.port = port
                else:
                    self.ip = ip1
                    self.port = port1
                self.request = NO_COMMAND
                self.req_socket = socket.socket(socket.AF_INET,
                                                socket.SOCK_STREAM)
                self.req_socket.connect((self.ip, self.port))
                self.my_socket = socket.socket(socket.AF_INET,
                                               socket.SOCK_STREAM)
                # connect to server
                self.my_socket.connect((self.ip, self.port))
                self.username = NO_USER
                self.password = NO_PASSWORD
                self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
                self.cloud = self.client_reg. \
                    read_registry(HKEY_LOCAL_MACHINE,
                                  CLIENT_REG, CLOUD_REG)
            elif constructor_mode == APP_MODE:
                self.request = NO_COMMAND
                reg_ip = ReadRegistry(SERVER_REG)  # client reading
                self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
                self.client_reg.set_observer(ALLOW_OBS)  # initiates
                ip1, port1 = reg_ip.get_ip_port()
                if ip is not None and port is not None:
                    self.ip = ip
                    self.port = port
                else:
                    self.ip = ip1
                    self.port = port1
                self.username = self.client_reg. \
                    read_registry(HKEY_LOCAL_MACHINE,
                                  CLIENT_REG, USERNAME_REG)
                self.password = self.client_reg. \
                    read_registry(HKEY_LOCAL_MACHINE,
                                  CLIENT_REG, PASSWORD_REG)
                self.cloud = self.client_reg. \
                    read_registry(HKEY_LOCAL_MACHINE,
                                  CLIENT_REG, CLOUD_REG)
                self.my_socket = socket.socket(socket.AF_INET,
                                               socket.SOCK_STREAM)
                # connect to server
                self.my_socket.connect((self.ip, self.port))
            elif constructor_mode == MID_GUI_MODE:
                reg = ReadRegistry(SERVER_REG)  # server cloud
                ip1, port1 = reg.get_ip_port()
                if ip is not None and port is not None:
                    self.ip = ip
                    self.port = port
                else:
                    self.ip = ip1
                    self.port = port1
                self.request = NO_COMMAND
                self.req_socket = socket.socket(socket.AF_INET,
                                                socket.SOCK_STREAM)
                self.req_socket.connect((self.ip, self.port))
                self.my_socket = socket.socket(socket.AF_INET,
                                               socket.SOCK_STREAM)
                # connect to server
                self.my_socket.connect((self.ip, self.port))
                self.client_reg = ReadRegistry(CLIENT_REG)  # client reading
                self.username = self.client_reg.read_registry(
                    HKEY_LOCAL_MACHINE, CLIENT_REG, USERNAME_REG)
                self.password = self.client_reg.read_registry(
                    HKEY_LOCAL_MACHINE, CLIENT_REG, PASSWORD_REG)
                self.cloud = self.client_reg. \
                    read_registry(HKEY_LOCAL_MACHINE,
                                  CLIENT_REG, CLOUD_REG)
        except Exception as msg:
            print("at constructor Client", msg)

    def initiate_listen(self):
        """
        :return: sends the server an hello command
        """
        message = self.username + SEPERATOR + REQ_SOCK_COMMAND
        self.send_request_to_server(self.req_socket, message)
        receive_requests = threading.Thread(target=self.recieving_requests)
        receive_requests.start()

    def recieving_requests(self):
        """
        :return: recieveing requests and handles them
        """
        try:
            while True:
                request_length = self.req_socket.recv(BYTE).decode()
                if request_length.isdigit():
                    request = self.req_socket.recv(
                        int(request_length)).decode()
                    req_and_prms = request.split(SEPERATOR)
                    from_user = BLANK
                    command = BLANK
                    params = []
                    if len(req_and_prms) >= TWO_PARAMETER:
                        from_user = req_and_prms.pop(START)
                        command = req_and_prms.pop(START)
                        params = req_and_prms
                    self.handle_server_request(from_user, command, params)
        except socket.error:
            pass
            self.client_reg.set_observer(
                DENY_OBS)  # so that folder manager will not be triggered

    def handle_server_request(self, from_user, command, params):
        """
        :return: handles request
        """
        if command == SHARE and \
                len(params) == ONE_PARAMETER:
            self.client_reg.set_observer(DENY_OBS)
            file = File(params[START])
            file_name = file.name + DOT + file.format
            message = from_user + " Wanted To Send You A File (" + file_name + ")"
            if win32ui.MessageBox(message, "Request Was Just Sent You",
                                  win32con.MB_YESNOCANCEL) == win32con.IDYES:
                message_for_server = self.username + SEPERATOR + COPY_FILE + SEPERATOR + from_user + SEPERATOR\
                                     + self.without_cloud(file.path)
                Client.send_request_to_server(self.my_socket,
                                              message_for_server)
                name = Client.read_server_response(self.my_socket).decode()
                file.set_name(name)
                file_to_save = file.make_new_file_path(self.cloud)
                Client.make_imaginary_file(file_to_save)
                time.sleep(LONG_SLEEP)
                self.client_reg.set_observer(ALLOW_OBS)
                print("received")
            else:
                message = self.username + SEPERATOR + DONT_SEND + SEPERATOR + from_user + SEPERATOR + file_name
                Client.send_request_to_server(self.my_socket, message)
        elif command == DONT_SEND and len(params) == ONE_PARAMETER:
            message = from_user + " Denied Your Offer Of " + params[START]
            win32ui.MessageBox(message, "Offer Denied",
                               win32con.MB_YESNOCANCEL)
        elif command == ASK_FOR_SHARE and len(params) == NO_PARAMETERS:
            message = from_user + " Wants To Access Your Files"
            if win32ui.MessageBox(message, "Request Was Just Sent You",
                                  win32con.MB_YESNOCANCEL) == win32con.IDYES:
                message = self.username + SEPERATOR + SEND_MY_FILES
                Client.send_request_to_server(self.req_socket, message)
            else:
                message = self.username + SEPERATOR + DENY_ACCESS
                Client.send_request_to_server(self.req_socket, message)
        elif command == DENY_ACCESS and len(params) == NO_PARAMETERS:
            message = from_user + " Denied Your Offer Of Accessing His Cloud"
            win32ui.MessageBox(message, "Offer Denied",
                               win32con.MB_YESNOCANCEL)
        elif command == ASK_FOR_FILE and len(params) == ONE_PARAMETER:
            file = File(params[START])
            message = from_user + " Wants You To Send Him %s" % file.path
            print(file.path)
            if win32ui.MessageBox(message, "Request Was Just Sent You",
                                  win32con.MB_YESNOCANCEL) == win32con.IDYES:
                file.set_format(CLOUD_FORMAT)
                print(file.path)
                message_for_server = self.username + SEPERATOR + SHARE + SEPERATOR + from_user + \
                                    SEPERATOR + file.path
                Client.send_request_to_server(self.my_socket,
                                              message_for_server)
            else:
                message = self.username + SEPERATOR + DONT_SEND + SEPERATOR + from_user + SEPERATOR + file_name
                Client.send_request_to_server(self.my_socket, message)

    def initiate_cloud(self):
        """
        :return: initiates cloud directory
        """
        if Client.valid_directory(self.cloud):
            ReadRegistry.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                      CLOUD_REG, self.cloud)
            return True
        return False

    def user_setup(self, username, password):
        """
       :return: sets the username and pass word to database
        """
        self.send_request_to_server(
            self.my_socket, self.username + SEPERATOR + NEW_USER + SEPERATOR +
            username + SEPERATOR + password)
        reply = Client.read_server_response(self.my_socket)
        if reply.decode() == USER_ADDED:
            self.username = username
            self.password = password
            ReadRegistry.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                      USERNAME_REG, self.username)
            ReadRegistry.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                      PASSWORD_REG, self.password)
        else:
            return False
        return True

    def user_login(self, username, password):
        """
        :return: nothing if everything works correctly
        """
        self.send_request_to_server(
            self.my_socket, self.username + SEPERATOR + LOG_IN + SEPERATOR +
            username + SEPERATOR + password)
        reply = Client.read_server_response(self.my_socket)
        if reply.decode() != FINE:
            return reply.decode()
        self.username = username
        self.password = password
        ReadRegistry.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG, USERNAME_REG,
                                  self.username)
        ReadRegistry.set_registry(HKEY_LOCAL_MACHINE, CLIENT_REG, PASSWORD_REG,
                                  self.password)
        return FINE

    def set_up(self):
        """
        creates a new directory under current cloud - where temporary
        files will be held, and folder manager file will be saved
        :return: -
        """
        # initiates temporary files directory
        if not os.path.isdir(self.cloud + APPINFO):
            os.mkdir(self.cloud + APPINFO)
        startup_dir = STARTUP_DIRECTORY % self.user_pc
        if not os.path.isfile(startup_dir + "\\Startup.pyw"):
            shutil.copy2(self.cloud + PATH_TO_STARTUP, startup_dir)
        if not os.path.isfile(self.cloud + "\\Cloudio.exe"):
            shutil.copy2(self.cloud + CLOUDIO_PATH, self.cloud)

    def upload_all(self):
        """
        :return: uploads all files to the cloud
        """
        files = []
        # r=root, d=directories, f = files
        for r, d, f in os.walk(self.cloud):
            if APPINFO not in r and CLOUDIO_NAME not in r:
                for file in f:
                    if File(file).get_format() != CLOUD_FORMAT:
                        files.append(os.path.join(r, file))
        for file in files:
            req = self.username + SEPERATOR + \
                  UPLOAD_FILE + SEPERATOR + self.without_cloud(file)
            self.send_request_to_server(self.my_socket, req)
            ans = self.read_server_response(self.my_socket)
            while not ans.decode() == READY:
                time.sleep(SHORT_SLEEP)
                print("%s LOADING...." % file)
                ans = self.read_server_response(self.my_socket)
            self.upload(file, self.my_socket)

    def without_cloud(self, request):
        """
        :return: converts a file path without client's cloud
        """
        return request.replace(self.cloud, BLANK)

    @staticmethod
    def send_request_to_server(server_socket, request):
        """
        Send the request to the server.
        First the length of the request (4 digits), then the request itself
        Example: '0004EXIT'
        Example: '0012DIR c:\cyber'
        """
        print(request)
        server_socket. \
            send((str(len(request)).zfill(MSG_FILL) + request).encode())

    def answer_all(self, requests):
        """
        :param requests: a string of requests
        :return: deals with all of them
        """
        requests_list = requests.split(REQUEST_SEPARATOR)
        for request in requests_list:
            req = request.split(SEPERATOR)
            from_user = req[START]
            command = req[SECOND]
            params = []
            if len(req) >= TWO_PARAMETER:
                params = req[THIRD:]
            self.handle_server_request(from_user, command, params)

    def handle_user_input(self):
        """
        :return: does what the client asks for
        """
        done = False
        # checks for requests while was down
        message = self.username + SEPERATOR + GET_REQUESTS
        self.send_request_to_server(self.my_socket, message)
        requests = self.read_server_response(self.my_socket)
        if requests.decode() != NO_REQUESTS and requests.decode(
        ) != SERVER_FELL:
            self.answer_all(requests.decode())
        # while the operation is not quit. if quit - go out
        while not done:
            # if not blank command
            # sends the operation to the server
            data = self.read_server_response(self.my_socket)
            if data is not None:
                if data.decode() == READY:
                    data = self.upload(self.request, self.my_socket)
                self.handle_server_response(data)
            if data.decode() == SERVER_FELL:
                win32ui.MessageBox("The Server Has Fallen Down",
                                   "Error At Cloud", win32con.MB_YESNOCANCEL)
                self.my_socket.close()
                try:
                    self.req_socket.close()
                except:
                    pass  # is the mode doesn't include a receiving socket
                self.client_reg.set_observer(
                    DENY_OBS)  # so that folder manager will not be triggered
                done = True

    @staticmethod
    def read_server_response(server_socket_choice):
        """
        reads the length and according to that, it reads the rest
        of the message
        """
        try:
            length_of_message = server_socket_choice.recv(BYTE).decode()
            if length_of_message.isdigit():
                return server_socket_choice.recv(int(length_of_message))
        except:
            return SERVER_FELL.encode()

    @staticmethod
    def handle_server_response(server_response):
        """
        :param server_response: the server'request response
        :return: handles the response
        """
        try:
            if server_response.decode() != BLANK:
                if server_response.decode() != SERVER_FELL:
                    print(server_response.decode())
                else:
                    print("\n\n******the server has fallen down******\n")
        except Exception as msg:
            print("at handle_server_response:", msg)

    @staticmethod
    def valid_file(path):
        """
        checks if the path is a file that exists
        """
        if os.path.isfile(path):
            return True
        return False

    def ask_for_share(self, user_to_ask):
        """
        :param user_to_ask: the username of the wanted user.
        :return: list of files of the user / 'permission denied' if doesnt allow
        """
        message = self.username + SEPERATOR + ASK_FOR_SHARE_BTN + SEPERATOR + user_to_ask
        Client.send_request_to_server(self.my_socket, message)
        reply = Client.read_server_response(self.my_socket)
        if reply != PERMISSION_DENIED:
            return reply
        return BLANK

    @staticmethod
    def send_response_to_server(message, client_socket_ex):
        """
        sends the server the answer to what it input
        """
        message_length = len(message.encode())
        good_length = str(message_length).zfill(BYTE).encode()
        client_socket_ex.send(good_length + message.encode())

    @staticmethod
    def send_binary_response_to_server(message, client_socket_ex):
        """
        sends the server the answer to what it input
        """
        message_length = len(message)
        good_length = str(message_length).zfill(BYTE).encode()
        client_socket_ex.send(good_length + message)

    def upload(self, file_path, my_socket):
        """
        Sends a file from the server to the client
        """
        if Client.valid_file(file_path):
            self.client_reg.set_observer(DENY_OBS)
            if File(file_path).get_format() != CLOUD_FORMAT:
                client_file = open(file_path, 'rb')
                content = client_file.read(BYTE_NUMBER)
                while content != BLANK.encode():
                    Client.send_binary_response_to_server(content, my_socket)
                    content = client_file.read(BYTE_NUMBER)
                client_file.close()
                Client.send_binary_response_to_server(FILE_END, my_socket)
                Client.delete_file(file_path)
                Client.make_imaginary_file(file_path)
                time.sleep(LONG_SLEEP)
                self.client_reg.set_observer(ALLOW_OBS)
                return Client.read_server_response(my_socket)
            else:
                return FILE_ALREADY_IN_CLOUD
        else:
            Client.send_response_to_server(FILE_DOESNT_EXIST, my_socket)
            return FILE_DOESNT_EXIST

    @staticmethod
    def delete_file(file_path):
        """
        deletes file
        """
        os.remove(file_path)

    @staticmethod
    def make_imaginary_file(file_path):
        """
        :param file_path: the file we want to be imaginary
        :return: -
        """
        new_file_path = File(file_path)
        new_file_path = new_file_path.change_file_to_cloud(CLOUD_FORMAT)
        i_file = open(new_file_path, 'wb')
        i_file.close()

    @staticmethod
    def valid_directory(folder):
        """
        :param folder: wanted folder
        :return: True - exists, False - otherwise
        """
        return os.path.isdir(folder)

    def end(self):
        """
        :return: closes all sockets of current client
        """
        self.my_socket.close()
        self.req_socket.close()
Exemple #7
0
class Application(object):
    def __init__(self):
        """
        :param request: the request of the file to receive from server
        """
        # initiates request (clicked file path)
        self.request = Application.get_request()
        self.client_reg = ReadRegistry(CLIENT_REG)
        self.server_key = OpenKey(HKEY_LOCAL_MACHINE, SERVER_REG,
                                  REGISTRY_ZERO, KEY_READ)
        self.client_key = OpenKey(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                  REGISTRY_ZERO, KEY_READ)

        ip, port = self.get_ip_port()
        self.ip = ip
        self.port = port
        self.cloud = Application.read_registry(HKEY_LOCAL_MACHINE, CLIENT_REG,
                                               CLOUD_REG)
        self.temp = self.cloud + APPINFO
        self.username = Application.read_registry(HKEY_LOCAL_MACHINE,
                                                  CLIENT_REG, USERNAME_REG)

        # initiates socket
        try:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.ip, self.port))
            # sends the request to the server
            path_to_send = self.without_cloud(self.request)
            Application.send_request_to_server(
                self.sock, self.username + SEPERATOR + DOWNLOAD_FILE +
                SEPERATOR + path_to_send)
            format = Application.read_server_response(self.sock).decode()
            if format != ERROR_FORMAT:
                self.path_file = self.download(format)
                self.start_file_and_wait()
                folder_comp = self.request.split("\\")
                fine_folder_comp = folder_comp[:END]
                folder = "\\".join(fine_folder_comp)
                # self.copy_file(self.path_file, folder)  # so we don't trigger watchdog
                self.upload()
                # src_path = sys.argv[SECOND]
                # new_file = src_path.split(".")[START] + "." + format
                # Application.delete_file(new_file)

            self.sock.close()
        except Exception as msg:
            print("connection error:", msg)

    @staticmethod
    def get_request():
        """
        :return: the full file path (if whitespace is in the path)
        """
        params = sys.argv
        file_path = ""
        for x in range(STARTER, len(params)):
            if DOT in params[x]:
                file_path += " " + params[x]
                break
            file_path += " " + params[x]
        return file_path[SECOND:]  # get rid of blank space

    def get_ip_port(self):
        """
        :return: ip and port of server
        """
        for i in range(VALUE_COUNT):
            try:
                name, value, typ = EnumValue(self.server_key, i)
                if name == "IP":
                    ip = value
                if name == "port":
                    port = value
            except EnvironmentError:
                print("You have ", i, " values")
                break
        CloseKey(self.server_key)
        return ip, port

    @staticmethod
    def read_registry(department, reg_path, value_name):
        """
        :param reg_path: path to key
        :param value_name: key
        :return: the key's value
        """
        key = OpenKey(department, reg_path, REGISTRY_ZERO, KEY_READ)
        for i in range(BIG_NUMBER):
            try:
                name, value, typ = EnumValue(key, i)
                if name == value_name:
                    return value
            except EnvironmentError:
                print("You have ", i, " values")
                break
        CloseKey(key)
        return ""

    def without_cloud(self, request):
        """
        :return: converts a file path without client's cloud
        """
        new_request = request.replace(self.cloud, '')
        if new_request[START] == " ":
            return new_request[STARTER:]
        return new_request

    @staticmethod
    def valid_file(path):
        """
        checks if the path is a file that exists
        """
        if os.path.isfile(path):
            return True
        return False

    @staticmethod
    def delete_file(file_path):
        """
        deletes file
        """
        os.remove(file_path)

    @staticmethod
    def read_server_response(server_socket_choice):
        """
        reads the length and according to that, it reads the rest
        of the message
        """
        try:
            length_of_message = server_socket_choice.recv(BYTE).decode()
            if length_of_message.isdigit():
                return server_socket_choice.recv(int(length_of_message))
        except Exception as msg:
            print("at read_server_response:", msg)
            return SERVER_FELL

    @staticmethod
    def send_request_to_server(server_socket, request):
        """
        Send the request to the server.
        First the length of the request (2 digits), then the request itself
        Example: '04EXIT'
        Example: '12DIR c:\cyber'
        """
        server_socket. \
            send((str(len(request)).zfill(MSG_FILL) + request).encode())

    def download(self, format):
        """
        saves the given chunks to a file in the client
        """
        try:
            file = Application.new_format_path(self.request, format)
            new_location = Application.make_new_file_path(self.temp, file)
            # check if the file is valid
            check_len = self.sock.recv(BYTE).decode()
            check = self.sock.recv(int(check_len))
            if check != FILE_DOESNT_EXIST:
                self.client_reg.set_observer(DENY_OBS)
                client_file = open(new_location, 'wb')
                # write what we took out
                client_file.write(check)
                done = False
                while not done:
                    byte_message_len = self.sock.recv(BYTE)
                    length = byte_message_len.decode()
                    if length.isdigit():
                        real_len = int(length)
                        data = self.sock.recv(real_len)
                    if data == FILE_END:
                        done = True
                    else:
                        client_file.write(data)
                client_file.close()
                self.client_reg.set_observer(ALLOW_OBS)
                return new_location
            else:
                return 'nothing'
        except Exception as msg:
            print("at download:", msg)

    def copy_file(self, origin, dest):
        """
        :param origin: the original file path
        :param dest: the destination
        :return: -
        """
        shutil.copy2(origin, dest)

    def upload(self):
        """
        Sends a file from the server to the client
        """
        if Application.valid_file(self.path_file):
            self.client_reg.set_observer(DENY_OBS)
            client_file = open(self.path_file, 'rb')
            content = client_file.read(BYTE_NUMBER)
            while content != b'':
                Application.send_binary_response_to_server(content, self.sock)
                content = client_file.read(BYTE_NUMBER)
            client_file.close()
            Application.send_binary_response_to_server(FILE_END, self.sock)
            Application.delete_file(self.path_file)
            self.client_reg.set_observer(ALLOW_OBS)
            return Application.read_server_response(self.sock)
        else:
            Application.send_response_to_server(FILE_DOESNT_EXIST, self.sock)
            return FILE_DOESNT_EXIST

    @staticmethod
    def send_response_to_server(message, client_socket_ex):
        """
        sends the server the answer to what it input
        """
        message_length = len(message.encode())
        good_length = str(message_length).zfill(BYTE).encode()
        client_socket_ex.send(good_length + message.encode())

    @staticmethod
    def make_new_file_path(new_path, folder):
        """
        :param new_path: new path of file to merge
        :return: the new path
        """
        comp = folder.split("\\")
        return new_path + "\\" + comp[END]

    @staticmethod
    def new_format_path(path, format):
        """
        :param format: the new format
        :return: the same path but with new format
        """
        path_format = path.split('.')
        path_format[SECOND] = format
        return ".".join(path_format)

    @staticmethod
    def send_binary_response_to_server(message, client_socket_ex):
        """
        sends the server the answer to what it input
        """
        message_length = len(message)
        good_length = str(message_length).zfill(BYTE).encode()
        client_socket_ex.send(good_length + message)

    def start_file_and_wait(self):
        """
        :param fname: the file path - temporary
        :return: opens and continues when closed
        """
        lst1 = psutil.pids()
        p = subprocess.Popen([self.path_file], shell=True)
        print(p)
        time.sleep(LONG_SLEEP)
        lst2 = psutil.pids()
        lst3 = [p for p in lst2 if p not in lst1]

        still_alive = lst3
        while len(still_alive) > 0:
            self.send_response_to_server(self.username + SEPERATOR + WAIT,
                                         self.sock)
            live_p = psutil.pids()
            still_alive = [p for p in lst3 if p in live_p]
            time.sleep(SHORT_SLEEP)
        self.send_response_to_server(self.username + SEPERATOR + CONTINUE,
                                     self.sock)