python ftp

#!/usr/bin/python
# -*- coding: UTF-8 -*-


import sys
import ftplib
import ConfigParser
import datetime
import os
import MySQLdb


#localhost
#10.4.211.158
def connect_mysql():
    db_config = dict(host="10.4.211.158", port=3306, db="ci_data", charset="utf8", user="root", passwd="123456")
    try:
        cnx = MySQLdb.connect(**db_config)
    except Exception as err:
        raise err
    return cnx


print connect_mysql()








time=datetime.datetime.now().strftime('%Y%m%d_%H%M%S_')


conf = ConfigParser.ConfigParser()
conf.read('setting.ini')      
host = conf.get("FTP", "host")
username = conf.get("FTP", "username")
password = '123456'
employee_id = conf.get("CFG", "id")
tfs= conf.get("CFG", "tfs").replace('"', "")
comment = conf.get("CFG", "comment").replace('"', "")
branch = conf.get("CFG", "branch").replace('"', "")


fileName = time + tfs + '.txt'
def ftp_upload():
    file_remote = fileName
    file_local = fileName
    bufsize = 1024  # 设置缓冲器大小
    fp = open(file_local, 'rb')
    f.storbinary('STOR ' + file_remote, fp, bufsize)
    fp.close()




f = ftplib.FTP(host)
f.login(username, password)


pwd_path = f.pwd()
f.cwd(pwd_path+'/CI')
a = f.dir()


try:
    f.cwd(employee_id)
except:  
    f.mkd(employee_id)
    f.cwd(employee_id)




def check_list():
	pass


#a = raw_input("input:")
checkDic = {}
rules = []
rules.append(  '01. 1!')
rules.append(  '02. 2!')
rules.append('''03. 3''')




print '*'*100
for rule in rules:
    while 1:
        print ''
        print rule
        print "\n0: q, 1: w"
        res = str(sys.stdin.readline()).replace("\n", "")
        if (res != '0') and (res != '1'):
            print "Error input:", res
            continue
        else:
            checkDic[rule] = res
        break


checkList=sorted(checkDic.iteritems(),key=lambda abs:abs[0],reverse=False)
out=open(fileName,'w')
for dic in checkList:
    key, value = dic
    print value.replace("\n", "") + '  |  ' + key + '\n'
    out.write(value.replace("\n", "") + '  |  ' + key + '\n')
    out.write('-'*100+'\n')
out.close()


ftp_upload()


if os.path.exists(fileName):
    os.remove(fileName)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值