paramiko.SFTPFile

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

## Type SFTPFile

      object --+
               |
    BufferedFile --+
                   |
                  SFTPFile

Proxy object for a file on the remote server, in client mode SFTP.

Method Summary
| `__init__(self, sftp, handle, mode, bufsize)`
| `__del__(self)`
str | ``check`(self, hash_algorithm, offset, length, block_size)` Ask the server for a hash of a section of this file.
| ``close`(self)` Close the file.
float | ``gettimeout`(self)` Returns the timeout in seconds (as a float) associated with the socket or ssh `Channel` used for this file.
| ``prefetch`(self)` Pre-fetch the remaining contents of this file in anticipation of future `read` calls.
| ``seek`(self, offset, whence)` Set the file's current position, like stdio's `fseek`.
| ``set_pipelined`(self, pipelined)` Turn on/off the pipelining of write operations to this file.
| ``setblocking`(self, blocking)` Set blocking or non-blocking mode on the underiying socket or ssh `Channel`.
| ``settimeout`(self, timeout)` Set a timeout on read/write operations on the underlying socket or ssh `Channel`.
SFTPAttributes | ``stat`(self)` Retrieve information about this file from the remote system.
Inherited from BufferedFile
iterator | ``__iter__`(self)` Returns an iterator that can be used to iterate over the lines in this file.
| ``flush`(self)` Write out any data in the write buffer.
str | ``next`(self)` Returns the next line from the input, or raises `StopIteration` when EOF is hit.
str | ``read`(self, size)` Read at most `size` bytes from the file (less if we hit the end of the file first).
str | ``readline`(self, size)` Read one entire line from the file.
list | ``readlines`(self, sizehint)` Read all remaining lines using `readline` and return them as a list.
int | ``tell`(self)` Return the file's current position.
| ``write`(self, data)` Write data to the file.
| ``writelines`(self, sequence)` Write a sequence of strings to the file.
iterator | ``xreadlines`(self)` Identical to `iter(f)`.
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)

Class Variable Summary
`int` | `MAX_REQUEST_SIZE` = 32768
Inherited from BufferedFile
`int` | `SEEK_CUR` = 1
`int` | `SEEK_END` = 2
`int` | `SEEK_SET` = 0

Method Details

### check(self, hash_algorithm, offset=0, length=0, block_size=0) Ask the server for a hash of a section of this file. This can be used to verify a successful upload or download, or for various rsync-like operations. The file is hashed from `offset`, for `length` bytes. If `length` is 0, the remainder of the file is hashed. Thus, if both `offset` and `length` are zero, the entire file is hashed. Normally, `block_size` will be 0 (the default), and this method will return a byte string representing the requested hash (for example, a string of length 16 for MD5, or 20 for SHA-1). If a non-zero `block_size` is given, each chunk of the file (from `offset` to `offset + length`) of `block_size` bytes is computed as a separate hash. The hash results are all concatenated and returned as a single string. For example, `check('sha1', 0, 1024, 512)` will return a string of length 40. The first 20 bytes will be the SHA-1 of the first 512 bytes of the file, and the last 20 bytes will be the SHA-1 of the next 512 bytes. Parameters: `hash_algorithm` - the name of the hash algorithm to use (normally `"sha1"` or `"md5"`) (type=str) `offset` - offset into the file to begin hashing (0 means to start from the beginning) (type=int or long) `length` - number of bytes to hash (0 means continue to the end of the file) (type=int or long) `block_size` - number of bytes to hash per result (must not be less than 256; 0 means to compute only one hash of the entire segment) (type=int) Returns: string of bytes representing the hash of each block, concatenated together (type=str) Raises: `IOError` - if the server doesn't support the "check-file" extension, or possibly doesn't support the hash algorithm requested Note: Many (most?) servers don't support this extension yet. Since: 1.4

### close(self, _async=False) Close the file. Future read and write operations will fail. Overrides: `paramiko.BufferedFile.close` (inherited documentation)

### gettimeout(self) Returns the timeout in seconds (as a float) associated with the socket or ssh `Channel` used for this file. Returns: float See Also: `Channel.gettimeout`

### prefetch(self) Pre-fetch the remaining contents of this file in anticipation of future `read` calls. If reading the entire file, pre-fetching can dramatically improve the download speed by avoiding roundtrip latency. The file's contents are incrementally buffered in a background thread. Since: 1.5.1

### seek(self, offset, whence=0) Set the file's current position, like stdio's `fseek`. Not all file objects support seeking. Parameters: `offset` - position to move to within the file, relative to `whence`. (type=int) `whence` - type of movement: 0 = absolute; 1 = relative to the current position; 2 = relative to the end of the file. (type=int) Raises: `IOError` - if the file doesn't support random access. Overrides: `paramiko.BufferedFile.seek` (inherited documentation) Note: If a file is opened in append mode (`'a'` or `'a+'`), any seek operations will be undone at the next write (as the file position will move back to the end of the file).

### set_pipelined(self, pipelined=True) Turn on/off the pipelining of write operations to this file. When pipelining is on, paramiko won't wait for the server response after each write operation. Instead, they're collected as they come in. At the first non-write operation (including `close`), all remaining server responses are collected. This means that if there was an error with one of your later writes, an exception might be thrown from within `close` instead of `write`. By default, files are not pipelined. Parameters: `pipelined` - `True` if pipelining should be turned on for this file; `False` otherwise (type=bool) Since: 1.5

### setblocking(self, blocking) Set blocking or non-blocking mode on the underiying socket or ssh `Channel`. Parameters: `blocking` - 0 to set non-blocking mode; non-0 to set blocking mode. (type=int) See Also: `Channel.setblocking`

### settimeout(self, timeout) Set a timeout on read/write operations on the underlying socket or ssh `Channel`. Parameters: `timeout` - seconds to wait for a pending read/write operation before raising `socket.timeout`, or `None` for no timeout (type=float) See Also: `Channel.settimeout`

### stat(self) Retrieve information about this file from the remote system. This is exactly like `SFTP.stat`, except that it operates on an already-open file. Returns: an object containing attributes about this file. (type=SFTPAttributes)

Class Variable Details

    ### MAX_REQUEST_SIZE Type: `int` Value:
        32768

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