Best Python code snippet using autotest_python
file2.py
Source:file2.py
1import os2from paramiko import Transport, SFTPClient3def remote_scp(ftp_type, host_ip, remote_path, local_path, username, password):4 ssh_port = 225 try:6 conn = Transport((host_ip, ssh_port))7 conn.connect(username=username, password=password)8 sftp = SFTPClient.from_transport(conn)9 if ftp_type == 'remoteRead':10 print('read')11 if not local_path:12 filename = os.path.split(remote_path)13 local_path = os.path.join('/tmp', filename[-1])14 print('å¼å§ä»æå¡å¨ä¸è½½æ件......')15 sftp.get(remote_path, local_path)16 print(f'æ件{filename[-1]}å·²ç»ä¸è½½å°æ¬å°')17 if ftp_type == "remoteWrite":18 print('write')19 sftp.put(local_path, remote_path)20 conn.close()21 return True22 except IOError as e:23 print('没ææ¾å°ç®å½', e)24 except Exception as e:25 print('error!!!', e)26remote_scp('remoteRead', '172.25.16.89', '/usr/local/aquila_pd_test/tomcat/dt.sh', '', 'aquila_pd_test', 'aquila_pd_test')...
download_info.py
Source:download_info.py
1# encoding:utf-82import paramiko3import os4def remote_scp():5 HOST_IP = '47.95.120.23'6 REMOTE_PATH = '/work/update_gdtcookies/'7 REMOTE_FILENAME = 'info.json'8 LOCAL_PATH = './'9 USERNAME = 'zmwork'10 PASSWORD = 'ab&C2S8$14Xr#s0o'11 if not os.path.isdir(LOCAL_PATH):12 os.makedirs(LOCAL_PATH)13 if not os.path.isfile(LOCAL_PATH + '/' + REMOTE_FILENAME):14 fp = open(LOCAL_PATH + '/' + REMOTE_FILENAME, 'w')15 fp.close()16 t = paramiko.Transport((HOST_IP, 22))17 t.connect(username=USERNAME, password=PASSWORD) # ç»å½è¿ç¨æå¡å¨18 sftp = paramiko.SFTPClient.from_transport(t) # sftpä¼ è¾åè®®19 src = REMOTE_PATH + '/' + REMOTE_FILENAME20 des = LOCAL_PATH + '/' + REMOTE_FILENAME21 sftp.get(src, des)22 t.close()23if __name__ == '__main__':...
download.py
Source:download.py
1import paramiko2import datetime3def remote_scp(host_ip, remote_path, local_path, username, password):4 t = paramiko.Transport((host_ip, 22))5 t.connect(username=username, password=password)6 sftp = paramiko.SFTPClient.from_transport(t)7 start_time = datetime.datetime.now()8 src = remote_path9 des = local_path10 sftp.get(src, des)11 t.close()12 end_time = datetime.datetime.now()13 c = 58 / (end_time - start_time).seconds14 print('ä¸è½½é度为:{}M/s'.format(c))15if __name__ == '__main__':16 host_ip = '192.168.1.115'17 remote_path = '/home/ifarm-lcc-exec.jar'18 local_path = r'c:\Users\a\ifarm-lcc-exec.jar'19 username = 'root'20 password = '123456'...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!