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

yipeiwu_com5年前服务器

如下所示:

# 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设计】。

相关文章

Spring Cloud微服务架构简介

Spring Cloud微服务架构简介

什么是微服务微服务架构风格是一种将一个单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中,服务间通信采用轻量级通信机制(通常用HTTP资源API)。这些服务围绕业务能力构建并且可通过全自...

基于并发服务器几种实现方法(总结)

今天主题是实现并发服务器,实现方法有多种版本,先从简单的单进程代码实现到多进程,多线程的实现,最终引入一些高级模块来实现并发TCP服务器。 说到TCP,想起吐槽大会有个段子提到三次握手,...

Python基于select实现的socket服务器

本文实例讲述了Python基于select实现的socket服务器。分享给大家供大家参考,具体如下: 借鉴了asyncore模块中select.select的使用方法 import...

Apache服务器无法使用的解决方法

原因一:80端口占用例如IIS,另外就是迅雷。我的apache服务器就是被迅雷害得无法启用!原因二:软件冲突装了某些软件会使apache无法启动如Dr.com 你打开网络连接->T...

centos+nginx+uwsgi+Django实现IP+port访问服务器

centos+nginx+uwsgi+Django实现IP+port访问服务器

环境 MacBookAir 阿里云ESC: Centos7.0 nginx+1.16.1 uwsgi=2.0.18 django=2.2.7 服务器 进入阿里云...