Package paramiko :: Class SFTPHandle
[show private | hide private]
[frames | no frames]

Type SFTPHandle

object --+
         |
        SFTPHandle


Abstract object representing a handle to an open file (or folder) in an SFTP server implementation. Each handle has a string representation used by the client to refer to the underlying file.

Server implementations can (and should) subclass SFTPHandle to implement features of a file handle, like stat or chattr.
Method Summary
  __init__(self)
int chattr(self, attr)
Change the attributes of this file.
  close(self)
When a client closes a file, this method is called on the handle.
str read(self, offset, length)
Read up to length bytes from this file, starting at position offset.
SFTPAttributes or error code stat(self)
Return an SFTPAttributes object referring to this open file, or an error code.
  write(self, offset, data)
Write data into this file at position offset.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

chattr(self, attr)

Change the attributes of this file. The attr object will contain only those fields provided by the client in its request, so you should check for the presence of fields before using them.
Parameters:
attr - the attributes to change on this file.
           (type=SFTPAttributes)
Returns:
an error code like SFTP_OK.
           (type=int)

close(self)

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 self named readfile and/or writefile, and if either or both are present, their close() 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.

read(self, offset, length)

Read up to length bytes from this file, starting at position offset. 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 self named readfile, 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 - position in the file to start reading from.
           (type=int or long)
length - number of bytes to attempt to read.
           (type=int)
Returns:
data read from the file, or an SFTP error code.
           (type=str)

stat(self)

Return an SFTPAttributes object referring to this open file, or an error code. This is equivalent to SFTPServerInterface.stat, except it's called on an open file instead of a path.
Returns:
an attributes object for the given file, or an SFTP error code (like SFTP_PERMISSION_DENIED).
           (type=SFTPAttributes or error code)

write(self, offset, data)

Write data into this file at position offset. Extending the file past its original end is expected. Unlike python's normal write() methods, this method cannot do a partial write: it must write all of data or else return an error.

The default implementation checks for an attribute on self named writefile, and if present, performs the write operation on the python file-like object found there. The attribute is named differently from readfile to 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 - position in the file to start reading from.
           (type=int or long)
data - data to write into the file.
           (type=str)
Returns:
an SFTP error code like SFTP_OK.

Generated by Epydoc 2.1 on Sun Dec 4 11:16:47 2005 http://epydoc.sf.net