Home  >  Article  >  Backend Development  >  An example of using paramiko to remotely copy files in python

An example of using paramiko to remotely copy files in python

高洛峰
高洛峰Original
2017-03-04 16:40:361819browse

The example of this article describes how python uses paramiko to realize remote copying of files. Share it with everyone for your reference, the details are as follows:

The first is to install the paramiko library (which implements the SSH2 security protocol), which can be installed directly from the source under ubuntu:

sudo apt-get install python-paramiko

The next step is the code to implement remote download:

def remote_scp(host_ip,remote_path,local_path,username,password):
  t = paramiko.Transport((host_ip,22))
  t.connect(username=username, password=password) # 登录远程服务器
  sftp = paramiko.SFTPClient.from_transport(t)  # sftp传输协议
  src = remote_path
  des = local_path
  sftp.get(src,des)
  t.close()

For more examples of python using paramiko to achieve remote copying of files, please pay attention to the PHP Chinese website for related articles. !

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn