Thomas Lester
Thomas Lester

Reputation: 192

pyftp put is truncating the file to 4096 bits

I'm writing a python script that uploads a cvs file to a remote host via sftp (using pysftp). Everything appears to be working fine, but the uploaded file is always truncated to 4096 bytes. If I upload the file from the os (linux) using sftp, everything works fine. Is there a default that is set somewhere to only allow 4096 byte files?

Here's the sftp part of my code:

def sftp_file():
try:
    s = sftp.Connection(host=dropbox, username='oemreport', private_key=private_key)
    s.put(report_file, export_file)
    s.close()

except Exception, e:
    print str(e)

Upvotes: 0

Views: 508

Answers (1)

ricardgf
ricardgf

Reputation: 458

If the file descriptor of "report_file" is open it won't upload the full file because it's not written entirely on disk yet.

You should close the file descriptor first.

report_file.close()

Upvotes: 1

Related Questions