Python 实现两个服务器之间文件的上传方法
如下所示:
#coding:utf-8
importparamiko
importMySQLdb
defmain():connection=MySQLdb.connect(host='10.10.41.22',user='root',passwd='root',db='Trojan',port=3306)
cur=connection.cursor()
sql='selectcount(*)fromblacklist;'
cur.execute(sql)
count=cur.fetchone()[0]
print'一共有%s个应用需要上传'%(count)
sql='selectpathfromblacklist;'
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
forpathincur.fetchall():
bendiPath="/home/wcloud/apk_baseinfo_mounted_point/apk%s"%path
apkName=bendiPath.split("/")[-1]
servicePath='/home/remote2/blacklist_wandoujia/%s'%apkName
printbendiPath
printservicePath
sftp.put(bendiPath,servicePath)
i=i+1
print'已经上传%s个应用,还有%d个应用没有上传'%(i,(count-i))
if__name__=='__main__':
main()
以上这篇Python实现两个服务器之间文件的上传方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短