在列表中给出超过19条记录,并通过给定的sftp连接细节将其传递到循环中,但在运行19条记录后出现了错误。以下是我的代码。
import paramiko
import sys, os
import time
lsit1 = ["CBCGG1900089HM", "CBCGG1900090HM", "CBCGG1900091HM", "CBCGG1900092HM", "CBCGG1900093HM", "CBCGG1900094HM", "CBCGG1900095HM", "CBCGG1900096HM", "CBCGG1900097HM", "CBCGG1900098HM", "CBCGG1900099HM", "CBCGG1900100", "CBCGG1900101HM", "CBCGG1900102HM", "CBCGG1900103HM", "CBCGG1900104HM", "CBCGG1900105HM", "CBCGG1900106HM", "CBCGG1900108HM", "CBCGG1900109HM", "CBCGG1900112HM", "CBCGG1900116HM", "CBCGG1900120HM", "CBCGG1900124HM", "CBCGG1900128HM", "CBCGG1900130HM", "CBCGG1900131HM", "CBCGG1900132HM", "CBCGG1900136HM", "CBCGG1900142HM", "CBCGG1900149HM", "CBCGG1900151HM", "CBCGG1900153", "CBCGG1900161", "CBDGG1900001", "BCYG1800038", "BCYG1800041", "BCYG1800045", "BCYG1800047", "BCYG1800049"]
col_id = []
def sftpfun(i):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='abc.com',timeout=6000,username='abc',password='xxbb')
ftp = ssh.open_sftp()
print("bc")
ftp.get(f'/CT_Logs/Optima660_Beijing/{i}/image_analysis.csv', f'/home/hvr/sftp_python/Optima660_Beijing {i}/image_analysis.csv')
ssh.close()
except:
col_id.append(f"Optima660_Beijing/{i}")
with open(f"/home/hvr/sftp_python/logs/sftp_logs.txt", 'w') as f:
f.write(i)
for i,j in zip(lsit1,range(len(lsit1))):
sftpfun(i)
if j%15==0:
time.sleep(15)