Skip to content

Commit 519d89c

Browse files
authored
Example (#240)
* Added sftp copy file example. Updated setup.py * Added single client example
1 parent 084696d commit 519d89c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

examples/sftp_copy_file.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
from gevent import joinall
3+
from datetime import datetime
4+
from pssh.clients import ParallelSSHClient
5+
6+
7+
with open('file_copy', 'wb') as fh:
8+
for _ in range(2000000):
9+
fh.write(b'asdfa')
10+
11+
12+
fileinfo = os.stat('file_copy')
13+
client = ParallelSSHClient(['localhost'])
14+
now = datetime.now()
15+
cmd = client.copy_file('file_copy', '/tmp/file_copy')
16+
joinall(cmd, raise_error=True)
17+
taken = datetime.now() - now
18+
mb_size = fileinfo.st_size / (1024000.0)
19+
rate = mb_size / taken.total_seconds()
20+
print("File size %sMB transfered in %s, transfer rate %s MB/s" % (
21+
mb_size, taken, rate))

examples/single_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pssh.clients import SSHClient
2+
from datetime import datetime
3+
4+
5+
host = 'localhost'
6+
cmds = ['echo first command',
7+
'echo second command',
8+
'sleep 1; echo third command took one second',
9+
]
10+
client = SSHClient(host)
11+
12+
start = datetime.now()
13+
for cmd in cmds:
14+
out = client.run_command(cmd)
15+
for line in out.stdout:
16+
print(line)
17+
end = datetime.now()
18+
print("Took %s seconds" % (end - start).total_seconds())

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
author='Panos Kittenis',
3232
author_email='zuboci@yandex.com',
3333
url="https://github.com/ParallelSSH/parallel-ssh",
34+
license='LGPLv2.1',
3435
packages=find_packages(
3536
'.', exclude=('embedded_server', 'embedded_server.*',
3637
'tests', 'tests.*',

0 commit comments

Comments
 (0)