当前位置: 编程技术>python
python 从远程服务器下载东西的代码
来源: 互联网 发布时间:2014-09-04
本文导语: 代码如下:# _*_ coding:utf-8 _*_# name gefile.pyimport osimport statimport socketimport paramikoFILES=["filenameA","filenameB","filenameC","filenameD","filenameE"]USERNAME="root"PASSWORD="123456"HOST="192.168.1.66"PORT=22remotefile="/root/filename"localpath=r'D:docsfilename_download'sock = soc...
代码如下:
# _*_ 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:docsfilename_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()