From 322c2624fc0e8d60856709d83421324594b3c3d0 Mon Sep 17 00:00:00 2001 From: Panos Date: Sat, 14 Nov 2020 22:14:43 +0000 Subject: [PATCH 1/2] Added sftp copy file example. Updated setup.py --- examples/sftp_copy_file.py | 21 +++++++++++++++++++++ setup.py | 1 + 2 files changed, 22 insertions(+) create mode 100644 examples/sftp_copy_file.py diff --git a/examples/sftp_copy_file.py b/examples/sftp_copy_file.py new file mode 100644 index 00000000..c5cb7bf3 --- /dev/null +++ b/examples/sftp_copy_file.py @@ -0,0 +1,21 @@ +import os +from gevent import joinall +from datetime import datetime +from pssh.clients import ParallelSSHClient + + +with open('file_copy', 'wb') as fh: + for _ in range(2000000): + fh.write(b'asdfa') + + +fileinfo = os.stat('file_copy') +client = ParallelSSHClient(['localhost']) +now = datetime.now() +cmd = client.copy_file('file_copy', '/tmp/file_copy') +joinall(cmd, raise_error=True) +taken = datetime.now() - now +mb_size = fileinfo.st_size / (1024000.0) +rate = mb_size / taken.total_seconds() +print("File size %sMB transfered in %s, transfer rate %s MB/s" % ( + mb_size, taken, rate)) diff --git a/setup.py b/setup.py index e487023c..ba14ff7b 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ author='Panos Kittenis', author_email='zuboci@yandex.com', url="https://github.com/ParallelSSH/parallel-ssh", + license='LGPLv2.1', packages=find_packages( '.', exclude=('embedded_server', 'embedded_server.*', 'tests', 'tests.*', From 4ba9f81012743a8853e4a4ad9f2bba4b913bfcca Mon Sep 17 00:00:00 2001 From: Panos Date: Sat, 14 Nov 2020 22:23:15 +0000 Subject: [PATCH 2/2] Added single client example --- examples/single_client.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/single_client.py diff --git a/examples/single_client.py b/examples/single_client.py new file mode 100644 index 00000000..0ab0fab5 --- /dev/null +++ b/examples/single_client.py @@ -0,0 +1,18 @@ +from pssh.clients import SSHClient +from datetime import datetime + + +host = 'localhost' +cmds = ['echo first command', + 'echo second command', + 'sleep 1; echo third command took one second', + ] +client = SSHClient(host) + +start = datetime.now() +for cmd in cmds: + out = client.run_command(cmd) + for line in out.stdout: + print(line) +end = datetime.now() +print("Took %s seconds" % (end - start).total_seconds())