Package paramiko :: Module sftp_client :: Class SFTPClient
[show private | hide private]
[frames | no frames]

Class SFTPClient

object --+    
         |    
  BaseSFTP --+
             |
            SFTPClient

Known Subclasses:
SFTP

SFTP client object. SFTPClient is used to open an sftp session across an open ssh Transport and do remote file operations.
Method Summary
  __init__(self, sock)
Create an SFTP client from an existing Channel.
  chmod(self, path, mode)
Change the mode (permissions) of a file.
  chown(self, path, uid, gid)
Change the owner (uid) and group (gid) of a file.
SFTPClient from_transport(selfclass, t)
Create an SFTP client channel from an open Transport. (Class method)
list of str listdir(self, path)
Return a list containing the names of the entries in the given path.
list of SFTPAttributes listdir_attr(self, path)
Return a list containing SFTPAttributes objects corresponding to files in the given path.
SFTPAttributes lstat(self, path)
Retrieve information about a file on the remote system, without following symbolic links (shortcuts).
  mkdir(self, path, mode)
Create a folder (directory) named path with numeric mode mode.
str normalize(self, path)
Return the normalized path (on the server) of a given path.
SFTPFile open(self, filename, mode, bufsize)
Open a file on the remote server.
str readlink(self, path)
Return the target of a symbolic link (shortcut).
  remove(self, path)
Remove the file at the given path.
  rename(self, oldpath, newpath)
Rename a file or folder from oldpath to newpath.
  rmdir(self, path)
Remove the folder named path.
SFTPAttributes stat(self, path)
Retrieve information about a file on the remote system.
  symlink(self, source, dest)
Create a symbolic link (shortcut) of the source path at destination.
  unlink(self, path)
Remove the file at the given path.
  utime(self, path, times)
Set the access and modified times of the file specified by path.
  _convert_status(self, msg)
Raises EOFError or IOError on error status; otherwise does nothing.
  _request(self, t, *arg)
    Inherited from BaseSFTP
  _log(self, level, msg)
  _read_all(self, n)
  _read_packet(self)
  _send_packet(self, t, packet)
  _send_server_version(self)
  _send_version(self)
  _write_all(self, out)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __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)
    Inherited from type
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T

Instance Method Details

__init__(self, sock)
(Constructor)

Create an SFTP client from an existing Channel. The channel should already have requested the "sftp" subsystem.

An alternate way to create an SFTP client context is by using from_transport.
Parameters:
sock - an open Channel using the "sftp" subsystem.
           (type=Channel)
Overrides:
paramiko.sftp.BaseSFTP.__init__

chmod(self, path, mode)

Change the mode (permissions) of a file. The permissions are unix-style and identical to those used by python's os.chmod function.
Parameters:
path - path of the file to change the permissions of.
           (type=string)
mode - new permissions.
           (type=int)

chown(self, path, uid, gid)

Change the owner (uid) and group (gid) of a file. As with python's os.chown function, you must pass both arguments, so if you only want to change one, use stat first to retrieve the current owner and group.
Parameters:
path - path of the file to change the owner and group of.
           (type=string)
uid - new owner's uid
           (type=int)
gid - new group id
           (type=int)

listdir(self, path)

Return a list containing the names of the entries in the given path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the folder. This method is meant to mirror os.listdir as closely as possible. For a list of full SFTPAttributes objects, see listdir_attr.
Parameters:
path - path to list.
           (type=str)
Returns:
list of filenames.
           (type=list of str)

listdir_attr(self, path)

Return a list containing SFTPAttributes objects corresponding to files in the given path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the folder.
Parameters:
path - path to list.
           (type=str)
Returns:
list of attributes.
           (type=list of SFTPAttributes)

Since: 1.2

lstat(self, path)

Retrieve information about a file on the remote system, without following symbolic links (shortcuts). This otherwise behaves exactly the same as stat.
Parameters:
path - the filename to stat.
           (type=string)
Returns:
an object containing attributes about the given file.
           (type=SFTPAttributes)

mkdir(self, path, mode=511)

Create a folder (directory) named path with numeric mode mode. The default mode is 0777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out.
Parameters:
path - name of the folder to create.
           (type=string)
mode - permissions (posix-style) for the newly-created folder.
           (type=int)

normalize(self, path)

Return the normalized path (on the server) of a given path. This can be used to quickly resolve symbolic links or determine what the server is considering to be the "current folder" (by passing '.' as path).
Parameters:
path - path to be normalized.
           (type=str)
Returns:
normalized form of the given path.
           (type=str)

open(self, filename, mode='r', bufsize=-1)

Open a file on the remote server. The arguments are the same as for python's built-in open (aka file). A file-like object is returned, which closely mimics the behavior of a normal python file object.

The mode indicates how the file is to be opened: 'r' for reading, 'w' for writing (truncating an existing file), 'a' for appending, 'r+' for reading/writing, 'w+' for reading/writing (truncating an existing file), 'a+' for reading/appending. The python 'b' flag is ignored, since SSH treats all files as binary. The 'U' flag is supported in a compatible way.
Parameters:
filename - name of the file to open.
           (type=string)
mode - mode (python-style) to open in.
           (type=string)
bufsize - desired buffering (-1 = default buffer size, 0 = unbuffered, 1 = line buffered, >1 = requested buffer size).
           (type=int)
Returns:
a file object representing the open file.
           (type=SFTPFile)
Raises:
IOError - if the file could not be opened.

readlink(self, path)

Return the target of a symbolic link (shortcut). You can use symlink to create these. The result may be either an absolute or relative pathname.
Parameters:
path - path of the symbolic link file.
           (type=str)
Returns:
target path.
           (type=str)

remove(self, path)

Remove the file at the given path.
Parameters:
path - path (absolute or relative) of the file to remove.
           (type=string)
Raises:
IOError - if the path refers to a folder (directory). Use rmdir to remove a folder.

rename(self, oldpath, newpath)

Rename a file or folder from oldpath to newpath.
Parameters:
oldpath - existing name of the file or folder.
           (type=string)
newpath - new name for the file or folder.
           (type=string)
Raises:
IOError - if newpath is a folder, or something else goes wrong.

rmdir(self, path)

Remove the folder named path.
Parameters:
path - name of the folder to remove.
           (type=string)

stat(self, path)

Retrieve information about a file on the remote system. The return value is an object whose attributes correspond to the attributes of python's stat structure as returned by os.stat, except that it contains fewer fields. An SFTP server may return as much or as little info as it wants, so the results may vary from server to server.

Unlike a python stat object, the result may not be accessed as a tuple. This is mostly due to the author's slack factor.

The fields supported are: st_mode, st_size, st_uid, st_gid, st_atime, and st_mtime.
Parameters:
path - the filename to stat.
           (type=string)
Returns:
an object containing attributes about the given file.
           (type=SFTPAttributes)

symlink(self, source, dest)

Create a symbolic link (shortcut) of the source path at destination.
Parameters:
source - path of the original file.
           (type=string)
dest - path of the newly created symlink.
           (type=string)

unlink(self, path)

Remove the file at the given path.
Parameters:
path - path (absolute or relative) of the file to remove.
           (type=string)
Raises:
IOError - if the path refers to a folder (directory). Use rmdir to remove a folder.

utime(self, path, times)

Set the access and modified times of the file specified by path. If times is None, then the file's access and modified times are set to the current time. Otherwise, times must be a 2-tuple of numbers, of the form (atime, mtime), which is used to set the access and modified times, respectively. This bizarre API is mimicked from python for the sake of consistency -- I apologize.
Parameters:
path - path of the file to modify.
           (type=string)
times - None or a tuple of (access time, modified time) in standard internet epoch time (seconds since 01 January 1970 GMT).
           (type=tuple of int)

_convert_status(self, msg)

Raises EOFError or IOError on error status; otherwise does nothing.

Class Method Details

from_transport(selfclass, t)

Create an SFTP client channel from an open Transport.
Parameters:
t - an open Transport which is already authenticated.
           (type=Transport)
Returns:
a new SFTPClient object, referring to an sftp session (channel) across the transport.
           (type=SFTPClient)

Generated by Epydoc 2.0 on Mon Feb 28 00:10:18 2005 http://epydoc.sf.net