import paramiko # pip install cx_Oracle -i https://mirrors.aliyun.com/pypi/simple/ host = 'ip' port = 22 username = '账户' password = '密码' remote_path = '服务器数据路径' local_path = './ddl_data/' # 创建一个SSH客户端 client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 连接到远程服务器 client.connect(hostname=host, port=port, username=username, password=password) # 创建一个SFTP客户端 sftp = client.open_sftp() # 获取远程目录下的所有文件 files = sftp.listdir(remote_path) # 遍历所有文件并下载到本地 for file in files: remote_file = remote_path + '/' + file local_file = local_path + '/' + file sftp.get(remote_file, local_file) # 关闭SFTP客户端和SSH客户端 sftp.close() client.close() # C_BAS_TX_BIL_TRX_INF
标签:remote,数据文件,python,sftp,client,file,linux,path,local From: https://www.cnblogs.com/wuzaipei/p/17250223.html