Python如何实现两个服务器之间文件的上传

来源:互联网 发布:node 构建项目 编辑:程序博客网 时间:2024/06/06 00:11
# coding: utf-8import paramikoimport MySQLdbdef 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()
原创粉丝点击