-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_remote_exec.py
More file actions
68 lines (58 loc) · 3.72 KB
/
test_remote_exec.py
File metadata and controls
68 lines (58 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Time: 2024/8/1 14:17
# Author: Luohaosen
# File: test_remote_exec.py
from app.remote_exec import RemoteControl
if __name__ == '__main__':
username = 'luohaosen'
password = 'XXXX'
control = RemoteControl(username=username, password=password, host='192.168.2.201', port_id=22)
# 文件上传测试
local_path = 'E:\\project\\pgs_statistics_report\\app\\test\\test.txt'
remote_path = '/ifs1/home/luohaosen/project/pgs_statistics_report/app/test/data/20240716_test/hello.txt'
control.run(mode='upload', local_path=local_path, server_path=remote_path)
# 文件夹上传测试
local_path = 'C:\\Users\\10291\\Desktop\\交付文件夹'
remote_path = '/ifs1/home/luohaosen/project/pgs_statistics_report/app/test/data/20240716_test/交付文件夹'
control.run(mode='upload', local_path=local_path, server_path=remote_path)
# 文件下载测试
remote_path = '/ifs1/home/luohaosen/project/pgs_statistics_report/app/test/data/20240716_test/hello.txt'
local_path = 'C:\\Users\\10291\\Desktop\\hello.txt'
control.run(mode='download', server_path=remote_path, local_path=local_path)
# 文件夹下载测试
remote_path = '/ifs1/home/luohaosen/project/pgs_statistics_report/app/test/data/20240716_test/交付文件夹'
local_path = 'C:\\Users\\10291\\Desktop\\交付文件夹_拷贝'
control.run(mode='download', server_path=remote_path, local_path=local_path)
# 执行命令
cmd = 'python /ifs1/home/luohaosen/project/pgs_statistics_report/app/test/test_sleep.py'
control.run(mode='execute', cmd=cmd)
# 关闭客户端
control.client.close()
"""
终端输出:
E:\project\pgs_statistics_report\venv\Scripts\python.exe E:/project/pgs_statistics_report/app/test/test_remote_exec.py
E:\project\pgs_statistics_report\venv\lib\site-packages\paramiko\pkey.py:100: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
"cipher": algorithms.TripleDES,
E:\project\pgs_statistics_report\venv\lib\site-packages\paramiko\transport.py:259: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
"class": algorithms.TripleDES,
2024-08-01 16:08:16,735 - Connected (version 2.0, client OpenSSH_8.0)
2024-08-01 16:08:16,763 - Authentication (password) successful!
2024-08-01 16:08:16,854 - [chan 0] Opened sftp connection (server version 3)
2024-08-01 16:08:16,856 - [chan 0] sftp session closed.
2024-08-01 16:08:16,864 - Connected (version 2.0, client OpenSSH_8.0)
2024-08-01 16:08:16,888 - Authentication (password) successful!
2024-08-01 16:08:16,971 - [chan 0] Opened sftp connection (server version 3)
2024-08-01 16:08:20,780 - [chan 0] sftp session closed.
2024-08-01 16:08:20,803 - Connected (version 2.0, client OpenSSH_8.0)
2024-08-01 16:08:20,828 - Authentication (password) successful!
2024-08-01 16:08:20,917 - [chan 0] Opened sftp connection (server version 3)
2024-08-01 16:08:20,923 - [chan 0] sftp session closed.
2024-08-01 16:08:20,931 - Connected (version 2.0, client OpenSSH_8.0)
2024-08-01 16:08:20,956 - Authentication (password) successful!
2024-08-01 16:08:21,050 - [chan 0] Opened sftp connection (server version 3)
2024-08-01 16:08:23,029 - [chan 0] sftp session closed.
2024-08-01 16:08:23,043 - Connected (version 2.0, client OpenSSH_8.0)
2024-08-01 16:08:23,068 - Authentication (password) successful!
2024-08-01 16:08:28,189 - 命令行执行,产生输出:
2024-08-01 16:08:28,189 - 返回状态码:0
进程已结束,退出代码为 0
"""