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()
下一篇: Python 中@property的用法