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

yipeiwu_com6年前服务器

如下所示:

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

相关文章

haskell实现多线程服务器实例代码

复制代码 代码如下:module Main where import Network.Socketimport Control.Concurrent main :: IO ()main...

php+javascript实现的动态显示服务器运行程序进度条功能示例

php+javascript实现的动态显示服务器运行程序进度条功能示例

本文实例讲述了php+javascript实现的动态显示服务器运行程序进度条功能。分享给大家供大家参考,具体如下: 经常有这样的业务要处理,服务器上有较多的业务需要处理,需要分批操作,于...

PHP连接Nginx服务器并解析Nginx日志的方法

php与nginx整合 PHP-FPM也是一个第三方的FastCGI进程管理器,它是作为PHP的一个补丁来开发的,在安装的时候也需要和PHP源码一起编译,也就是说PHP-FPM被编译到P...

python脚本监控Tomcat服务器的方法

python脚本监控Tomcat服务器的方法

文章出处:https://blog.csdn.net/sdksdk0/article/details/80933444 作者:朱培    &nb...

python定时采集摄像头图像上传ftp服务器功能实现

首先是截图,从摄像头截取一幅图像: 复制代码 代码如下:while 1:   #测试摄像头的存在    try:  ...