Skip to content

Commit 912974c

Browse files
author
Pan
committed
Updated readme
1 parent f98fb1d commit 912974c

File tree

1 file changed

+170
-28
lines changed

1 file changed

+170
-28
lines changed

README.rst

Lines changed: 170 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,156 @@ Super fast SSH2 protocol library. ``ssh2-python`` provides Python bindings for `
1010
:target: https://pypi.python.org/pypi/ssh2-python
1111
:alt: Latest Version
1212

13-
Features
14-
---------
1513

16-
Majority of the `libssh2`_ API has been implemented as Python native code extensions. ``ssh2-python`` is a thin wrapper of ``libssh2`` - ``libssh2`` code examples can be ported straight over to Python with only minimal changes.
14+
Installation
15+
______________
1716

18-
*Library is usable for testing purposes and at the moment available as source code only. API, module names and documentation not yet finalised. Contributions welcome.*
17+
Install ``libssh2`` and Python header files.
1918

20-
SSH Functionality provided
21-
++++++++++++++++++++++++++++
19+
Ubuntu
20+
----------
2221

23-
* SSH channel operations (exec,shell,subsystem)
24-
* SSH agent
25-
* Public key authentication and management
26-
* SFTP
27-
* SCP
28-
* SSH port forwarding and tunnelling
29-
* Non-blocking mode
30-
* Listener for port forwarding
22+
.. code-block:: shell
3123
32-
And more, as per `libssh2`_ functionality.
24+
apt-get install libssh2-1-dev python-dev
25+
pip install ssh2-python
3326
3427
35-
Native Code Extension Features
36-
+++++++++++++++++++++++++++++++
28+
RedHat
29+
-------
30+
31+
.. code-block:: shell
3732
38-
The library uses `Cython`_ based native code extensions as wrappers to ``libssh2``.
33+
yum install libssh2-devel python-dev
34+
pip install ssh2-python
3935
40-
Extension features:
4136
42-
* Thread safe - GIL is released as much as possible
43-
* Very low overhead
44-
* Super fast as a consequence of the excellent C library it uses and that it uses native code prodigiously
45-
* Object oriented - memory freed automatically and safely as objects expire
46-
* Use Python semantics where applicable, such as iterator support for SFTP file handles
47-
* Expose errors as Python exceptions where possible
48-
* Provide access to ``libssh2`` error code definitions
37+
Feature Set
38+
_____________
39+
40+
Majority of the `libssh2`_ API has been implemented. ``ssh2-python`` is a thin wrapper of ``libssh2`` - its code examples can be ported straight over to Python with only minimal changes.
41+
42+
Some parts are yet to be implemented though majority of the API is complete. Note current restriction on byte strings in examples section.
43+
44+
*Library is at the moment available as source code only. Binary releases to follow.*
45+
46+
47+
Examples
48+
___________
49+
50+
Currently all string arguments are assumed to be byte strings - Python 3 users should use ``b'<string>'``.
51+
52+
See `Complete Example`_ for a complete example including socket connect.
53+
54+
55+
Authentication Methods
56+
-------------------------
57+
58+
59+
Connect and get available authentication methods.
60+
61+
62+
.. code-block:: python
63+
64+
from __future__ import print_function
65+
66+
from ssh2.session import Session
67+
68+
sock = <create and connect socket>
69+
70+
session = Session()
71+
session.handshake(sock)
72+
print(session.userauth_list())
73+
74+
75+
.. code-block:: python
76+
77+
['publickey', 'password', 'keyboard-interactive']
78+
79+
80+
Agent Authentication
81+
------------------------
82+
83+
84+
.. code-block:: python
85+
86+
session.agent_auth(user)
87+
88+
89+
Command Execution
90+
------------------------
91+
92+
93+
.. code-block:: python
94+
95+
channel = session.open_session()
96+
channel.execute('echo Hello')
97+
98+
99+
Reading Output
100+
---------------
101+
102+
.. code-block:: python
103+
104+
size, data = channel.read()
105+
while(size > 0):
106+
print(data)
107+
size, data = channel.read()
108+
109+
.. code-block:: python
110+
111+
Hello
112+
113+
114+
Exit Code
115+
--------------
116+
117+
.. code-block:: python
118+
119+
print("Exit status: {}".format(channel.get_exit_status()))
120+
121+
122+
.. code-block:: python
49123
124+
Exit status: 0
125+
126+
127+
Public Key Authentication
128+
----------------------------
129+
130+
.. code-block:: python
131+
132+
session.userauth_publickey_fromfile(
133+
username, 'my_pkey.pub', 'my_pkey', '')
134+
135+
136+
Where ``''`` can be a passphrase.
137+
138+
139+
Password Authentication
140+
----------------------------
141+
142+
143+
.. code-block:: python
144+
145+
session.userauth_password(
146+
username, '<my password>')
147+
148+
SFTP Read
149+
-----------
150+
151+
.. code-block:: python
50152
51-
Example
52-
--------
153+
sftp = session.sftp_init()
154+
fh = sftp.open(<file path>, 0, 0)
155+
with open(<file to write>, 'wb') as local_fh:
156+
for data in fh:
157+
local_fh.write(data)
158+
fh.close()
159+
160+
161+
Complete Example
162+
__________________
53163

54164
A simple usage example looks very similar to ``libssh2`` `usage examples <https://www.libssh2.org/examples/>`_.
55165

@@ -93,6 +203,38 @@ Clients using this library can be much simpler to use than interfacing with the
93203
Exit status: 2
94204

95205

206+
SSH Functionality currently provided
207+
_____________________________________
208+
209+
210+
* SSH channel operations (exec,shell,subsystem)
211+
* SSH agent
212+
* Public key authentication and management
213+
* SFTP
214+
* SCP
215+
* SSH port forwarding and tunnelling
216+
* Non-blocking mode
217+
* Listener for port forwarding
218+
219+
And more, as per `libssh2`_ functionality.
220+
221+
222+
Native Code Extension Features
223+
_______________________________
224+
225+
The library uses `Cython`_ based native code extensions as wrappers to ``libssh2``.
226+
227+
Extension features:
228+
229+
* Thread safe - GIL is released as much as possible
230+
* Very low overhead
231+
* Super fast as a consequence of the excellent C library it uses and that it uses native code prodigiously
232+
* Object oriented - memory freed automatically and safely as objects expire
233+
* Use Python semantics where applicable, such as iterator support for SFTP file handles
234+
* Expose errors as Python exceptions where possible
235+
* Provide access to ``libssh2`` error code definitions
236+
237+
96238
Comparison with other Python SSH2 libraries
97239
---------------------------------------------
98240

0 commit comments

Comments
 (0)