Skip to content

ftplib retrbinary(rest=...) seems to send incorrect data #127561

@zeddit

Description

@zeddit

Bug report

Bug description:

blocksize = 8192 #262144 # default 8192
local_tmp_filepath.touch(exist_ok=True)
## backward 1 blocksize to ensure data correctness
request_offset = max(0, local_tmp_filepath.stat().st_size - blocksize)
if request_offset > 0:
	print(f"continue downloading at position {request_offset}.")
with local_tmp_filepath.open('r+b') as f:
	f.seek(request_offset)
	ftp_hook.get_conn().retrbinary(f"RETR {str(remote_filepath)}",
				f.write, rest=request_offset, blocksize=blocksize)

when I used the code above to download some ftp files from the server, there would be a condition that my file finish downloaded has a byte of 32768 larger than it should be.

I don't know what's wrong with it, it's conditional, about 1~2 time in 10 downloads. great thanks!

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions