Python 实现两个服务器之间文件的上传方法

yipeiwu_com4年前服务器

如下所示:

# coding: utf-8
import paramiko
import MySQLdb

def main(): connection=MySQLdb.connect(host='10.10.41.22',user='root',passwd='root',db='Trojan',port=3306)

 cur=connection.cursor()

 sql ='select count(*) from blacklist;'
 cur.execute(sql)
 count = cur.fetchone()[0]
 print '一共有%s个应用需要上传'%(count)

 sql = 'select path from blacklist;'
 cur.execute(sql)
 host = '10.10.41.22'
 port = 22
 username = 'remote2'
 password = 'userforremote'
 t = paramiko.Transport((host,port))
 t.connect(username=username,password=password)
 sftp = paramiko.SFTPClient.from_transport(t)

 i=0

 for path in cur.fetchall():
  bendiPath = "/home/wcloud/apk_baseinfo_mounted_point/apk%s"%path
  apkName =bendiPath.split("/")[-1]
  servicePath = '/home/remote2/blacklist_wandoujia/%s'%apkName
  print bendiPath
  print servicePath
  sftp.put(bendiPath,servicePath)
  i=i+1
  print '已经上传%s个应用,还有%d个应用没有上传'%(i,(count-i))


if __name__ == '__main__':
 main()

以上这篇Python 实现两个服务器之间文件的上传方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python XML RPC服务器端和客户端实例

Python XML RPC服务器端和客户端实例

一、远程过程调用RPC XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a tra...

Web服务器框架 Tornado简介

Tornado 跟其他主流的Web服务器框架(主要是Python框架)不同是采用epoll非阻塞IO,响应快速,可处理数千并发连接,特别适用用于实时的Web服务。 高性能web服务器框架...

PHP实现检测客户端是否使用代理服务器及其匿名级别

要判断客户端是否使用代理服务器,可以从客户端所发送的环境变量信息来判断。 具体来说,就是看HTTP_VIA字段,如果这个字段设置了,说明客户端使用了代理服务器。 匿名级别可以参考下表来判...

python创建一个最简单http webserver服务器的方法

本文实例讲述了python创建一个最简单http webserver服务器的方法。分享给大家供大家参考。具体实现方法如下: import sys import BaseHTTPSer...

python实现TCP服务器端与客户端的方法详解

本文实例讲述了python实现TCP服务器端与客户端的方法。分享给大家供大家参考。具体如下: TCP服务器程序(tsTserv.py): from socket import * f...