Package paramiko :: Module sftp_si :: Class SFTPServerInterface
[show private | hide private]
[frames | no frames]

Type SFTPServerInterface

object --+
         |
        SFTPServerInterface


This class defines an interface for controlling the behavior of paramiko when using the SFTPServer subsystem to provide an SFTP server.

Methods on this class are called from the SFTP session's thread, so you can block as long as necessary without affecting other sessions (even other SFTP sessions). However, raising an exception will usually cause the SFTP session to abruptly end, so you will usually want to catch exceptions and return an appropriate error code.
Method Summary
  canonicalize(self, path)
Return the canonical form of a path on the server.
list of SFTPAttributes or error code list_folder(self, path)
Return a list of files within a given folder.
  lstat(self, path)
override -> SFTPAttributes
  stat(self, path)
override -> SFTPAttributes
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __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

canonicalize(self, path)

Return the canonical form of a path on the server. For example, if the server's home folder is /home/foo, the path "../betty" would be canonicalized to "/home/betty". Note the obvious security issues: if you're serving files only from a specific folder, you probably don't want this method to reveal path names outside that folder.

You may find the python methods in os.path useful, especially os.path.normpath and os.path.realpath.

The default implementation returns os.path.normpath('/' + path).

list_folder(self, path)

Return a list of files within a given folder. The path will use posix notation ("/" separates folder names) and may be an absolute or relative path.

The list of files is expected to be a list of SFTPAttributes objects, which are similar in structure to the objects returned by os.stat. In addition, each object should have its filename field filled in, since this is important to a directory listing and not normally present in os.stat results.
Parameters:
path - the requested path (relative or absolute) to be listed.
           (type=str)
Returns:
a list of the files in the given folder, using SFTPAttributes objects.
           (type=list of SFTPAttributes or error code)

Note: You should normalize the given path first (see the os.path module) and check appropriate permissions before returning the list of files. Be careful of malicious clients attempting to use relative paths to escape restricted folders, if you're doing a direct translation from the SFTP server path to your local filesystem.

lstat(self, path)

override -> SFTPAttributes

stat(self, path)

override -> SFTPAttributes

Generated by Epydoc 2.1 on Sat Oct 23 00:25:24 2004 http://epydoc.sf.net