当前位置:脚本大全 > > 正文

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

时间:2022-03-31 19:17:38类别:脚本大全

python把文件上传服务器

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

如下所示:

  • ?
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • # 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 实现两个服务器之间文件的上传方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。

    原文链接:https://blog.csdn.net/lzbhnr/article/details/78499427

    上一篇下一篇

    猜您喜欢

    热门推荐