当前位置 : 主页 > 手机开发 > ROM >

paramiko向服务器自动上传下载文件

来源:互联网 收集:自由互联 发布时间:2021-06-10
import paramiko import os def download_from(ip,u,p): file_list=[‘file2‘,file3‘,‘file4‘] file_path="/home/projs/" client=paramiko.Transport((ip,22)) client.connect(username=u,password=p) sftp=paramiko.SFTPClient.from_transport(clie

import paramiko
import os

def download_from(ip,u,p):
  file_list=[‘file2‘,file3‘,‘file4‘]
  file_path="/home/projs/"
  client=paramiko.Transport((ip,22))
  client.connect(username=u,password=p)
  sftp=paramiko.SFTPClient.from_transport(client)

  for file in file_list:
    sftp.get(os.path.join(file_path,file),os.path.join(‘local_path‘,file))
  client.close()

def put_to(ip,u,p):
  file_path="E:\\"
  remote_path=‘/home/ubuntu/‘
  client=paramiko.Transport((ip,22))
  client.connect(username=u,password=p)
  sftp=paramiko.SFTPClient.from_transport(client)
  for file in os.listdir(file_path):
    file_s=os.path.join(file_path,file)
    if os.path.isfile(file_s):
      sftp.put(file_s,os.path.join(remote_path,file))

  client.close()

网友评论