Description
SUMMARY
I'm trying to download configuration file from remote router and getting only last chunk of the file.
ISSUE TYPE
- Bug Report
PYLISSH and LIBSSH VERSION
0.4.0
OS / ENVIRONMENT
Ubuntu 22.04 LTS
Python 3.10.4
STEPS TO REPRODUCE
Narrowing the problem I wrote a piece of code below.
You need a file on remote host to reproduce it.
from pylibsshext.session import Session, AutoAddPolicy
hssh = Session()
p = AutoAddPolicy()
hssh.set_missing_host_key_policy(p)
HOST = 'hostname'
USER = 'username'
PASSWORD = 'password'
TIMEOUT = 30
PORT = 22
hssh.connect(
host=HOST,
user=USER,
password=PASSWORD,
timeout=TIMEOUT,
port=PORT,
)
sftp = hssh.sftp()
sftp.get('m8.rsc', 'm8.rsc')
EXPECTED RESULTS
File 'm8.rsc' in current directory, size of 16K
ACTUAL RESULTS
File 'm8.rsc', containing last 223b of source file.
As I found out, the problem lays in line #103 of sftp.pyx
with open(local_file, 'wb+') as f:
In python3, "w" parameter truncates the file, so during reading the source file new data overwrites old.
Please check and consider changing open mode to 'ab'