0

I have written this code that's suppose to send files over FTP. The problem is that in 3/5 cases the files are not fully getting to the other side -- I understand you have to use retrieve. I am writing this code for work so ignore the obnoxious "REDACTED" parts of the code. Currently, the only files that are reaching the other side in full are the .bin file and the Image file. -- They are the two smallest files as the other ones are quite big (the biggest is 19000 kb.) When the files are downloaded, they are very small compared to their original size. 35 kb compared to 10000 kb. 141 kb compared to 14000 kb. etc.

ftp = FTP('REDACTED')  
ftp.login('REDACTED', 'REDACTED')
print ("Opening FTP...\n")
   with open ('REDACTED.gz.uboot') as f: 
    print ('writing file...REDACTED.gz.uboot') 
    ftp.storbinary('STOR %s' % 'REDACTED.gz.uboot', f)

with open('REDACTED_Image', 'rb') as x:
    print ("writing file...REDACTED_Image")
    ftp.storbinary('STOR %s' % 'Image', f)

with open('REDACTED.rbf', 'rb') as f:  
    ftp.storbinary('STOR %s' % 'huh.rbf', f)
    print ("writing file...m0_host_top.rbf")

with open ('REDACTED.tar.bz2') as f:
    print ('writing file...REDACTED')
    ftp.storbinary('STOR %s' % 'REDACTED', f)

with open ('REDACTED.bin') as f:
    print ('writing file...REDACTED.bin')
    ftp.storbinary('STOR %s' % 'REDACTED.bin', f)

Any help here would be greatly appreciated, I need to get the full files across. Edit: I am presuming that there is an issue with the upload because each time the files are uploaded, they are of different sizes.

Cwhelden
  • 21
  • 4
  • Just to clarify, I have a script running locally that uses retrieve. Once the binary files are across. But the full binary files are not getting across all the way – Cwhelden Nov 16 '17 at 04:23
  • It could be. But I've attempted the upload several times, and each time that I attempt it, the files are of a different size when the upload is finished. – Cwhelden Nov 16 '17 at 12:01
  • Show us ftplib log (`FTP.set_debuglevel`) and server-side log, if you have an access to it. – Martin Prikryl Nov 16 '17 at 14:13

1 Answers1

0

As you are sending all the file in binary mode, you should open all the files with 'rb' mode.

Default open() will use the text mode to open a file, which means treats all the content as text.However you have some binary file like REDACTED.tar.bz2 in the case above. Using text mode to read these files will make the file content different from the origin one.

This question may help you on open() : Difference between parsing a text file in r and rb mode:

jacky15
  • 41
  • 3