ssh2.sftp_handle¶
SFTP handle, attributes and stat VFS classes.
- class ssh2.sftp_handle.SFTPHandle¶
- close(self)¶
Close handle. Called automatically when object is deleted and/or garbage collected.
- Return type
int
- fsetstat(self, SFTPAttributes attrs)¶
Set file handle attributes.
- Parameters
attrs (
ssh2.sftp.SFTPAttributes
) – Attributes to set.
- fstat(self)¶
Get file stat attributes from handle.
- Return type
ssh2.sftp.SFTPAttributes
or LIBSSH2_ERROR_EAGAIN
- fstat_ex(self, SFTPAttributes attrs, int setstat)¶
Get or set file attributes. Clients would typically use one of the fstat or fsetstat functions instead
- fstatvfs(self)¶
Get file system statistics for handle
- Return type
ssh2.sftp.SFTPStatVFS
- fsync(self)¶
Sync file handle data.
Available from libssh2 >=
1.4.4
- Return type
int
- read(self, size_t buffer_maxlen=c_ssh2.LIBSSH2_CHANNEL_WINDOW_DEFAULT)¶
Read buffer from file handle.
- Parameters
buffer_maxlen (int) – Max length of buffer to return.
- Returns
Size and buffer tuple.
- Return type
(int, bytes)
- readdir(self, size_t buffer_maxlen=1024)¶
Get directory listing from file handle, if any.
This function is a generator and should be iterated on.
File handle must be opened with
ssh2.sftp.SFTP.readdir()
- Parameters
buffer_maxlen – Max length of returned file entry.
- Return type
iter(bytes)
- readdir_ex(self, size_t longentry_maxlen=1024, size_t buffer_maxlen=1024)¶
Get directory listing from file handle, if any.
File handle must be opened with
ssh2.sftp.SFTP.readdir()
This function is a generator and should be iterated on.
- Parameters
buffer_maxlen – Max length of returned buffer.
longentry_maxlen – Max length of file list entry.
- Return type
bytes
- rewind(self)¶
Rewind file handle to beginning of file.
- Return type
None
- seek(self, size_t offset)¶
Deprecated, use seek64.
Seek file to given offset.
- Parameters
offset (int) – Offset to seek to.
- Return type
None
- seek64(self, libssh2_uint64_t offset)¶
Seek file to given 64-bit offset.
- Parameters
offset (int) – Offset to seek to.
- Return type
None
- tell(self)¶
Deprecated, use tell64.
Get current file handle offset.
- Return type
int
- tell64(self)¶
Get current file handle 64-bit offset.
- Return type
int
- write(self, bytes buf)¶
Write buffer to file handle.
Returns tuple of (
error code
,bytes written
).In blocking mode
bytes_written
will always equallen(buf)
if no errors have occurred which would raise exception.In non-blocking mode
error_code
can be LIBSSH2_ERROR_EAGAIN andbytes_written
can be less thanlen(buf)
.Clients should resume from that point on next call to
write
, iebuf[bytes_written_in_last_call:]
.- Parameters
buf (bytes) – Buffer to write.
- Return type
tuple(int, int)
- class ssh2.sftp_handle.SFTPStatVFS¶
File system statistics
- f_bavail¶
Free blocks for non-root
- f_bfree¶
Free blocks
- f_blocks¶
Size of fs in f_frsize units
- f_bsize¶
File system block size
- f_favail¶
Free inodes for non-root
- f_ffree¶
Free inodes
- f_files¶
Inodes
- f_flag¶
File system mount flags.
This property is a bit mask with defined bits
LIBSSH2_SFTP_ST_RDONLY
andLIBSSH2_SFTP_ST_NOSUID
- f_frsize¶
Fragment size
- f_fsid¶
File system ID
- f_namemax¶
Maximum filename length