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

相关文章

PHP实现Socket服务器的代码

PHP实现Socket服务器的代码

<?php ob_implicit_flush(); set_time_limit(0); $address = "192.40.7.93";//换成你自己的地...

浅析使用Python搭建http服务器

浅析使用Python搭建http服务器

David Wheeler有一句名言:“计算机科学中的任何问题,都可以通过加上另一层间接的中间层解决。”为了提高Python网络服务的可移植性,Python社区在PEP 333中提出了...

python检测服务器端口代码实例

这篇文章主要介绍了python检测服务器端口代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 import socket s...

Python Web程序搭建简单的Web服务器

Python Web程序搭建简单的Web服务器

上一篇讲了《Python入门》Windows 7下Python Web开发环境搭建笔记,接下来讲一下Python语言Web服务的具体实现:第一个Python Web程序——简单的Web服...

PyQt+socket实现远程操作服务器的方法示例

PyQt+socket实现远程操作服务器的方法示例

来需求了。。干活啦。。 需求内容 部分时候由于缓存刷新、验证码显示不出来或者浏览器打不开或者打开速度很慢等原因,导致部分测试同事不想使用浏览器登录服务器执行命令。 期望有小工具可以替代登...