You are here

Paramiko's SFTPFile.truncate()

Paramiko is the go-to module for utilizing SSH/SFTP in Python. One one the best features of Paramiko is being able to being able to SFTPClient.open() a remote file and simply use it like you would use a local file. SFTPClient's open() returns an SFTPFile which is a file-like object that implements theoretically the same behavior as Python's native file object.

But the catch here is file-like. It is like a file, except when it is not like a file.

The non-likeness I encountered concern's SFTPFile's truncate method. The native Python file object has a truncate method where the size is optional, if not specified it will default to the current offset of the file. However SFTPClient's truncate method requires the size to be specified. Failure to specify an size value results in a TypeError exception concerning incorrect number of parameters.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer