| 9 | |
| 10 | |
| 11 | class ftp_controller: |
| 12 | #/!\ Although the comments and variable names say 'file_name'/'file_anything' it inculdes folders also |
| 13 | #Some functions in this class has no exception handling, it has to be done outside |
| 14 | |
| 15 | def __init__(self): |
| 16 | #List to store file search and search keywords |
| 17 | self.search_file_list = [] |
| 18 | self.detailed_search_file_list = [] |
| 19 | self.keyword_list = [] |
| 20 | |
| 21 | #Variable to hold the max no character name in file list (used for padding in GUIs) |
| 22 | self.max_len = 0 |
| 23 | |
| 24 | self.max_len_name = '' |
| 25 | |
| 26 | #Variable to tell weather hidden files are enabled |
| 27 | self.hidden_files = False |
| 28 | |
| 29 | #Variable to store the platform the server is running on |
| 30 | self.server_platform = 'Linux' |
| 31 | |
| 32 | def connect_to(self, host, username = ' ', password = ' ', port = 21): |
| 33 | self.ftp = FTP() |
| 34 | self.ftp.connect(host, port) |
| 35 | self.ftp.login(username, password) |
| 36 | |
| 37 | def toggle_hidden_files(self): |
| 38 | self.hidden_files = not self.hidden_files |
| 39 | |
| 40 | def get_detailed_file_list(self, ignore_hidden_files_flag = False): |
| 41 | files = [] |
| 42 | def dir_callback(line): |
| 43 | if(self.server_platform != 'Linux'): |
| 44 | files.append(line) |
| 45 | return |
| 46 | if(self.hidden_files is True or line.split()[8][0] is not '.') or ignore_hidden_files_flag == True: |
| 47 | files.append(line) |
| 48 | self.ftp.dir(dir_callback) |
| 49 | return files |
| 50 | |
| 51 | def get_file_list(self, detailed_file_list): |
| 52 | self.max_len = 0 |
| 53 | self.max_len_name = '' |
| 54 | file_list = [] |
| 55 | for x in detailed_file_list: |
| 56 | #Remove details and append only the file name |
| 57 | if(self.server_platform == 'Linux'): |
| 58 | name = self.get_properties(x)[0] |
| 59 | file_list.append(name) |
| 60 | if(len(name) > self.max_len): |
| 61 | self.max_len = len(name) |
| 62 | self.max_len_name = name |
| 63 | return file_list |
| 64 | |
| 65 | def get_detailed_search_file_list(self): |
| 66 | return self.detailed_search_file_list |
| 67 | |
| 68 | def get_search_file_list(self): |
no outgoing calls
no test coverage detected