@@ -7,14 +7,14 @@ SSH library [paramiko](https://github.com/paramiko/paramiko/).
77## Installation
88Run:
99```
10- pip3 install --user sshcontroller-oroques
10+ pip3 install --user sshcontroller
1111```
1212
13- Note that the package has been exclusively tested on Python 3+.
13+ Note that the package has been exclusively tested on Python 3.6 +.
1414
1515## Usage
1616
17- The code snippets can also be found at [ demo.py] ( ./examples/demo.py ) .
17+ All code snippets can also be found at [ demo.py] ( ./examples/demo.py ) .
1818
1919#### 1. Create a new SSH controller from a SSH key
2020``` python
@@ -26,7 +26,7 @@ KEY_PWD = "password"
2626ssh_controller = sshcontroller.SSHController(
2727 host = HOST_IP ,
2828 user = " olivier" ,
29- key_path = " ~/.ssh/id_rsa" , # if omitted, look in agent and in ~/.ssh
29+ key_path = " ~/.ssh/id_rsa" , # if omitted, look for keys in SSH agent and in ~/.ssh/
3030 key_password = KEY_PWD , # optional
3131 key_type = " rsa" , # rsa (default), dsa, ecdsa or ed25519
3232 port = 22 , # 22 is the default
@@ -43,11 +43,11 @@ ssh_controller.connect()
4343return_code, output = ssh_controller.run(
4444 command = " echo 'Hello world!' > /tmp/hello.txt" ,
4545 display = True , # display output, false by default
46- combine_stderr = False , # combine stderr and stdout, false by default
4746 capture_output = True , # return output, false by default
47+ combine_stderr = False , # combine stderr and stdout, false by default
4848 timeout = 10 , # command timeout in seconds, 600s by default
4949)
50- logging.info (f " return code: { return_code} , output: { output} " )
50+ print (f " return code: { return_code} , output: { output} " )
5151```
5252
5353#### 4. Transfer data with SFTP
@@ -56,10 +56,10 @@ All functions from paramiko's `SFTPClient` are available through the
5656[ paramiko's documentation] ( http://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_client.SFTPClient )
5757for a complete list.
5858
59- In addition, the package adds new methods:
59+ In addition, the package implements additional methods:
6060* ` exists(path) ` : check that a file or a directory exists on the remote host
6161* ` list_dirs(path) ` : return the list of directories present in ` path `
62- * ` list_dirs (path)` : return the list of files present in ` path `
62+ * ` list_files (path)` : return the list of files present in ` path `
6363
6464``` python
6565print (f " hello.txt exists: { ssh_controller.exists(' /tmp/hello.txt' )} " )
@@ -77,29 +77,29 @@ with open("/tmp/bonjour.txt", 'r') as bonjour:
7777ssh_controller.disconnect()
7878```
7979
80- #### 6. Use SSH password instead
80+ #### 6. Use a SSH password instead of a key
8181``` python
8282import sshcontroller
8383
8484HOST_IP = " 93.184.216.34" # an IPv4 or IPv6 address
85- SSH_PWD = " "
85+ SSH_PWD = " password "
8686
8787ssh_controller = sshcontroller.SSHController(
8888 host = HOST_IP ,
89- user = " root " ,
89+ user = " olivier " ,
9090 ssh_password = SSH_PWD
9191)
9292ssh_controller.connect()
9393```
9494
9595#### 7. Run a command until an event is set
96- If the argument ` stop_event ` is set when calling ` run() ` , the controller waits
97- for the given event to be triggered before stopping. This is especially useful
98- when using threads.
96+ If the argument ` stop_event ` is set when calling ` run() ` , the controller
97+ ignores ` timeout ` and stops only when the given event is triggered instead.
98+ This is especially useful when using threads.
9999
100100The example below starts two threads with an event attached to each one:
101101one is pinging localhost, the other sleeps for 10s. When the sleeping threads
102- has finished, we trigger the events to also stop the pinging thread.
102+ has finished, the events are triggered to also stop the pinging thread.
103103
104104``` python
105105import logging
@@ -108,6 +108,8 @@ import sshcontroller
108108import threading
109109import time
110110
111+ # ... set up ssh_controller here ...
112+
111113output = queue.Queue() # a queue to store the ping command output
112114stop_event_sleep = threading.Event()
113115stop_event_ping = threading.Event()
0 commit comments