python 从远程服务器下载东西的代码
程序员文章站
2022-12-27 08:50:11
复制代码 代码如下:# _*_ 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()
上一篇: js求1到任意数之间的所有质数