(self, file_name, file_size, status_command, replace_command)
| 171 | return |
| 172 | |
| 173 | def upload_file(self, file_name, file_size, status_command, replace_command): |
| 174 | def update_progress(data): |
| 175 | self.bytes_uploaded += int(sys.getsizeof(data)) |
| 176 | status_command(file_name, str(min(round((self.bytes_uploaded/file_size) * 100, 8), 100))+'%') |
| 177 | #Variable to keep trak of number of bytes uploaded |
| 178 | self.bytes_uploaded = 0 |
| 179 | #Check if the file is already present in ftp server |
| 180 | if(self.is_there(file_name)): |
| 181 | if(replace_command(file_name, 'File exists in destination folder') is False): |
| 182 | return |
| 183 | #Try to open file, if fails return |
| 184 | try: |
| 185 | file_to_up = open(file_name, 'rb') |
| 186 | except: |
| 187 | status_command(file_name, 'Failed to open file') |
| 188 | return |
| 189 | #Try to upload file |
| 190 | try: |
| 191 | status_command(file_name, 'Uploading') |
| 192 | self.ftp.storbinary('STOR '+file_name, file_to_up, 8192, update_progress) |
| 193 | status_command(None, 'newline') |
| 194 | except: |
| 195 | status_command(file_name, 'Upload failed') |
| 196 | return |
| 197 | #Close file |
| 198 | file_to_up.close() |
| 199 | |
| 200 | def upload_dir(self, dir_name, status_command, replace_command): |
| 201 | #Change to directory |
no test coverage detected