欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 从远程服务器下载东西的代码

程序员文章站 2022-05-14 08:57:48
复制代码 代码如下:# _*_ coding:utf-8 _*_# name gefile.pyimport osimport statimport socketimpor...
复制代码 代码如下:

# _*_ coding:utf-8 _*_
# name gefile.py
import os
import stat
import socket
import paramiko
files=["filenamea","filenameb","filenamec","filenamed","filenamee"]
username="root"
password="123456"
host="192.168.1.66"
port=22
remotefile="/root/filename"
localpath=r'd:\docs\filename_download'
sock = socket.socket(socket.af_inet, socket.sock_stream)
sock.connect((host,port))
t = paramiko.transport(sock)
t.start_client()
t.auth_password(username,password)
sftptest=paramiko.sftpclient.from_transport(t)
sftptest.get(remotefile,localpath)
sftptest.close()
t.close()
sock.close()