##############################
#Wesley Venters
#Kali Linux python
#Ftp
##############################
from ftplib import FTP
#global variables
METHOD = 10
IP = "138.47.99.163"
Port = 21
FOLDER = "FILES"
contents = []
directory = ""
test = ""
covert = ""
output = ""
counter = 0
user = "valkyrie"
passwd = "readytoride"
#ftp connection and driectory grab
ftp= FTP()
ftp.connect(IP,Port)
ftp.login(user,passwd)
ftp.cwd(FOLDER)
ftp.dir(contents.append)
ftp.quit()
#decode function for binary generated by directories
def decode(binary, n):
        text = ""
        i = 0
        while (i < len(binary)):
                byte = binary[i:i+n]
                byte = int(byte, 2)
                if(byte==8):#checks if the integer is th ascii value for backspace
                    text = text[:-1]#removes the last character of the string text
                if(byte!=8):#if it isnt backspace then it continues as normal
                    text += chr(byte)
                i += n

        return text

for row in contents:
    row = row.split(" ")#splits each row of directory by spaces
    if METHOD == 7:# the seven bit method
        directory = row[0]
        test = directory[:3]#tests for --- in the first three bits
        covert = directory[3:]#ignores everything except the last 7 bits
        #print directory
        if test == "---":#if it isnt a trash bi
            for i in covert:
                if i != "-":
                    output += "1"# if it is filled put a 1
                elif i == "-":
                    output += "0"#if a dash put a 0
        text = decode(output, 7)# decode binary to text

    if METHOD == 10:
        directory = row[0]
        for i in directory:
            if i != "-":
                output+= "1"
            elif i == "-":
                output += "0"
        #if output %10 == 0:
        text = decode(output, 7)

print text
    
        







 

