MCPcopy Create free account
hub / github.com/RainingComputers/whipFTP / download_file

Method download_file

FTP_controller.py:227–253  ·  view source on GitHub ↗
(self, ftp_file_name, file_size, status_command, replace_command)

Source from the content-addressed store, hash-verified

225 os.chdir('..')
226
227 def download_file(self, ftp_file_name, file_size, status_command, replace_command):
228 #Function for updating status and writing to file
229 def write_file(data):
230 self.bytes_downloaded += int(sys.getsizeof(data))
231 status_command(ftp_file_name, str(min(round((self.bytes_downloaded/file_size) * 100, 8), 100))+'%')
232 file_to_down.write(data)
233 #Variable to keep track of total bytes downloaded
234 self.bytes_downloaded = 0
235 #Check if the file is already present in local directory
236 if(isfile(ftp_file_name)):
237 if(replace_command(ftp_file_name, 'File exists in destination folder') is False):
238 return
239 #Try to open file, if fails return
240 try:
241 file_to_down = open(ftp_file_name, 'wb')
242 except:
243 status_command(ftp_file_name, 'Failed to create file')
244 return
245 #Try to upload file
246 try:
247 status_command(ftp_file_name, 'Downloading')
248 self.ftp.retrbinary('RETR '+ftp_file_name, write_file)
249 status_command(None, 'newline')
250 except:
251 status_command(ftp_file_name, 'Download failed')
252 #Close file
253 file_to_down.close()
254
255 def download_dir(self, ftp_dir_name, status_command, replace_command):
256 #Create local directory

Callers 3

copy_fileMethod · 0.95
download_dirMethod · 0.95
downloadMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected