2

I've got a problem with the ftplib library when I'm uploading .gz files.

The script was working before but somehow in one of my thousands of editions, I changed something that is causing to transfer corrupted files. The files is successfully transferred to the ftp server, however, that files when is being used in the ftp won't open because is corrupted.

The files which are going to be transferred are without any issues. Also if the files are not compressed, the transfer has not any issues. It's something with the way it reads .gz

Can anyone let me know what is wrong with the code?

for filename in dir:

    os.system("gzip %s/%s" % (Path, filename))
    time.sleep(5)  # Wait up to 4 seconds to compress file
    zip_filename = filename + '.gz'

    try:
        # Connect to the host
        ftp = ftplib.FTP(host)
        # Login to the ftp server
        ftp.login(username, password)

        # Transfer the file
        myfile = open(zip_filename, 'rb')
        ftp.storlines("STOR temp/" + zip_filename, myfile)
        myfile.close()

    except ftplib.all_errors as e:
        print(e)
ultraInstinct
  • 4,063
  • 10
  • 36
  • 53

1 Answers1

1

The issue was the use of storlines. In this case, needs to be use storbinary

ultraInstinct
  • 4,063
  • 10
  • 36
  • 53