Skip to content

Commit

Permalink
Updated sftp open documentation, example and readme for compatibility.
Browse files Browse the repository at this point in the history
Resolves #13.
  • Loading branch information
pkittenis committed Feb 14, 2018
1 parent 545b0f3 commit 7ddc350
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ API Feature Set
________________


Currently the vast majority of the `libssh2`_ API has been implemented with only few exceptions.
At this time all of the `libssh2`_ API has been implemented up to version ``1.8.0``.

Complete example scripts for various operations can be found in the `examples directory`_.

Expand Down Expand Up @@ -179,9 +179,12 @@ SFTP Read

.. code-block:: python
from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR
sftp = session.sftp_init()
with sftp.open(<remote file to read>, 0, 0) as remote_fh, \
open(<file to write>, 'wb') as local_fh:
with sftp.open(<remote file to read>,
LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR) as remote_fh, \
open(<local file to write>, 'wb') as local_fh:
for size, data in remote_fh:
local_fh.write(data)
Expand Down Expand Up @@ -247,6 +250,7 @@ ________________________________________
* SCP send and receive
* Listener for port forwarding
* Subsystem support
* Host key checking and manipulation

And more, as per `libssh2`_ functionality.

Expand Down
3 changes: 2 additions & 1 deletion examples/sftp_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from datetime import datetime

from ssh2.session import Session
from ssh2.sftp import LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR


USERNAME = pwd.getpwuid(os.geteuid()).pw_name
Expand All @@ -37,7 +38,7 @@ def main():
sftp = s.sftp_init()
now = datetime.now()
print("Starting read for remote file %s" % (args.file,))
with sftp.open(args.file, 0, 0) as fh:
with sftp.open(args.file, LIBSSH2_FXF_READ, LIBSSH2_SFTP_S_IRUSR) as fh:
for size, data in fh:
pass
print("Finished file read in %s" % (datetime.now() - now,))
Expand Down
2 changes: 1 addition & 1 deletion ssh2/sftp.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ssh2/sftp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ cdef class SFTP:
:param filename: Name of file to open.
:type filename: str
:param flags: One or more LIBSSH2_FXF_* flags. Can be ``0`` for
reading.
:param flags: One or more LIBSSH2_FXF_* flags.
Eg for reading flags is ``LIBSSH2_FXF_READ``,
for writing ``LIBSSH2_FXF_WRITE``,
for both ``LIBSSH2_FXF_READ`` | ``LIBSSH2_FXF_WRITE``.
:type flags: int
:param mode: File permissions mode. ``0`` for reading.
:param mode: File permissions mode. ``LIBSSH2_SFTP_S_IRUSR`` for
reading.
For writing one or more LIBSSH2_SFTP_S_* flags.
For writing one or more ``LIBSSH2_SFTP_S_*`` flags.
Eg, for 664 permission mask (read/write owner/group, read other),
Expand Down

0 comments on commit 7ddc350

Please sign in to comment.