| 1 |
Receive file contents from remote SSH account |
| 2 |
----------------------------------------------------- |
| 3 |
|
| 4 |
Here is some small server code that you can use to retrieve |
| 5 |
contents of remote files: |
| 6 |
|
| 7 |
.. include:: servefiles.py |
| 8 |
:literal: |
| 9 |
|
| 10 |
And here is some code to use it to retrieve remote contents:: |
| 11 |
|
| 12 |
import execnet |
| 13 |
import servefiles |
| 14 |
gw = execnet.makegateway("ssh=codespeak.net") |
| 15 |
channel = gw.remote_exec(servefiles) |
| 16 |
|
| 17 |
for fn in ('/etc/passwd', '/etc/group'): |
| 18 |
channel.send(fn) |
| 19 |
content = channel.receive() |
| 20 |
print(fn) |
| 21 |
print(content) |