sshmitm.forwarders.sftp module
- class sshmitm.forwarders.sftp.SFTPBaseHandle(server_interface, session, plugin, filename, open_flags, open_attr, flags=0, *, use_buffer=False)
Bases:
SFTPHandle- Parameters:
server_interface (
BaseSFTPServerInterface)session (
Session)plugin (
type[SFTPHandlerBasePlugin])filename (
str)open_flags (
int)open_attr (
SFTPAttributes)flags (
int, default:0)use_buffer (
bool, default:False)
- close()
When a client closes a file, this method is called on the handle. Normally you would use this method to close the underlying OS level file object(s).
The default implementation checks for attributes on
selfnamedreadfileand/orwritefile, and if either or both are present, theirclose()methods are called. This means that if you are using the default implementations of read and write, this method’s default implementation should be fine also.- Return type:
None
- open_remote_file()
- Return type:
int|None
- read(offset, length)
Read up to
lengthbytes from this file, starting at positionoffset. The offset may be a Python long, since SFTP allows it to be 64 bits.If the end of the file has been reached, this method may return an empty string to signify EOF, or it may also return
SFTP_EOF.The default implementation checks for an attribute on
selfnamedreadfile, and if present, performs the read operation on the Python file-like object found there. (This is meant as a time saver for the common case where you are wrapping a Python file object.)- Parameters:
offset (
int) – position in the file to start reading from.length (
int) – number of bytes to attempt to read.length
- Return type:
bytes|int- Returns:
the bytes read, or an error code int.
- write(offset, data)
Write
datainto this file at positionoffset. Extending the file past its original end is expected. Unlike Python’s normalwrite()methods, this method cannot do a partial write: it must write all ofdataor else return an error.The default implementation checks for an attribute on
selfnamedwritefile, and if present, performs the write operation on the Python file-like object found there. The attribute is named differently fromreadfileto make it easy to implement read-only (or write-only) files, but if both attributes are present, they should refer to the same file.- Parameters:
offset (
int) – position in the file to start reading from.data (
ReadableBuffer) – data to write into the file.data
- Return type:
int- Returns:
an SFTP error code like
SFTP_OK.
- class sshmitm.forwarders.sftp.SFTPHandlerBasePlugin(sftp, filename)
Bases:
SSHMITMBaseModuleSpecifies the handler for SFTP operations, responsible for processing file transfer requests and managing file system interactions.
- Parameters:
sftp (
SFTPBaseHandle)filename (
str)
- close()
- Return type:
None
- classmethod get_file_handle()
- Return type:
type[SFTPBaseHandle]
- classmethod get_interface()
- Return type:
type[BaseSFTPServerInterface] |None
- handle_data(data, *, offset=None, length=None)
- Parameters:
data (
bytes)offset (
int|None, default:None)length (
int|None, default:None)
- Return type:
bytes
- property session: Session
- class sshmitm.forwarders.sftp.SFTPHandlerPlugin(sftp, filename)
Bases:
SFTPHandlerBasePluginTransparent SFTP plugin — forwards all data unchanged.
This is the base class for all SFTP plugins. Inherit from this class to implement custom SFTP behaviour; override only the methods you need.
- Parameters:
sftp (
SFTPBaseHandle)filename (
str)