Package paramiko :: Module sftp :: Class SFTP
[show private | hide private]
[frames | no frames]

Class SFTP

object --+
         |
        SFTP


Method Summary
  __init__(self, sock)
  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.
  from_transport(selfclass, t)
(Class method)
list of string listdir(self, path)
Return a list containing the names of the entries 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.
SFTPFile open(self, filename, mode, bufsize)
Open a file on the remote server.
string 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.
  _log(self, level, msg)
  _read_all(self, n)
  _read_packet(self)
  _request(self, t, *arg)
  _send_packet(self, t, packet)
  _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

Class Variable Summary
int _FXF_APPEND = 4                                                                     
int _FXF_CREATE = 8                                                                     
int _FXF_EXCL = 32                                                                    
int _FXF_READ = 1                                                                     
int _FXF_TRUNC = 16                                                                    
int _FXF_WRITE = 2                                                                     

Instance Method Details

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.
Parameters:
path - path to list.
           (type=string)
Returns:
list of filenames.
           (type=list of string)

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)

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=string)
Returns:
target path.
           (type=string)

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 Variable Details

_FXF_APPEND

Type:
int
Value:
4                                                                     

_FXF_CREATE

Type:
int
Value:
8                                                                     

_FXF_EXCL

Type:
int
Value:
32                                                                    

_FXF_READ

Type:
int
Value:
1                                                                     

_FXF_TRUNC

Type:
int
Value:
16                                                                    

_FXF_WRITE

Type:
int
Value:
2                                                                     

Generated by Epydoc 2.0 on Sun Jun 27 13:06:21 2004 http://epydoc.sf.net