FTP library error: received more than 8192 bytes

Python error loading a file larger than 8192 bytes. And the exception is only "received more than 8192 bytes." Is there a solution for downloading large files.

try: ftp = ftplib.FTP(str_ftp_server ) ftp.login(str_ftp_user, str_ftp_pass) except Exception as e: print('Connecting ftp server failed') return False try: print('Uploading file ' + str_param_filename) file_for_ftp_upload = open(str_param_filename, 'r') ftp.storlines('STOR ' + str_param_filename, file_for_ftp_upload) ftp.close() file_for_ftp_upload.close() print('File upload is successful.') except Exception as e: print('File upload failed !!!exception is here!!!') print(e.args) return False return True 
+7
python file-upload ftp
source share
2 answers

storlines reads a text file one line at a time, and 8192 is the maximum size of each line. You should probably use it since the heart of your download function is:

 with open(str_param_filename, 'rb') as ftpup: ftp.storbinary('STOR ' + str_param_filename, ftpup) ftp.close() 

This reads and saves in binary form one block at a time (8192 by default), but should work fine for files of any size.

+7
source share

I had a similar problem and it was solved by increasing the value of the ftplib maxline variable. You can set it to any integer value you want. It represents the maximum number of characters per line in your file. This affects the download and download.

I would recommend using ftp.storbinary in most cases to answer Alex Martelli, but this was not an option in my case (and not the norm).

 ftplib.FTP.maxline = 16384 # This is double the default value 

Just call this line at any time before starting the file transfer.

0
source share

All Articles