コード例 #1
0
def putSMB(task, file):
    try:
        samba = SMBConnection(task.username, task.password, 'mybase',
                              task.target)
        samba.connect(task.dir, int(task.port))
        list = task.tables.split(' ')
        share = list[0]  #TESt
        path = list[1]  #/
        s = file.split('/')[1]
        l = len(s) + 1 + 5
        t = file[l:]  #temp/share/  ddddd
        if path[-1] == '/':
            path += t  #/ddd
        else:
            path = path + '/' + t
        # 取路径
        dir = os.path.split(path)[0]
        # 去除首位空格
        dir = dir.strip()
        # 去除尾部 \ 符号
        dir = dir.rstrip("\\")
        if dir != '/':
            mkdir(samba, share, dir)
        with open(file, 'rb') as f:
            samba.storeFile(share, path, f)
        return True
    except Exception as e:
        LOGR.error('发送SMB文件错误:' + str(e))
コード例 #2
0
def putMySQL(configItem, file):

    try:
        conn = mysql.connector.connect(host=configItem.dir,
                                       user=configItem.username,
                                       password=configItem.password,
                                       database=configItem.target)
        cur = conn.cursor()
        with open(file, 'rb') as f:
            data = pickle.load(f)
        #拼凑导入sql
        table = os.path.basename(file).split('.')[0]
        sql = 'INSERT INTO ' + table + ' VALUES('
        length = len(data[0])
        for i in range(length):
            sql += '%s'
            if i < length - 1:
                sql += ','
        sql += ')'
        #导入
        for i in data:
            exec(cur, sql, i)
        conn.commit()
        conn.close()
    except Exception as e:
        LOGR.error('写入数据库出错:' + str(e))
        return False
    return True
コード例 #3
0
def putFile(task, file):
    try:
        path = task.dir.strip("/")
        path.strip()
        isExists = os.path.exists(path)
        if not isExists:
            os.makedirs(path)
        shutil.copy(file, path)
        return True
    except Exception as e:
        LOGR.error('文件复制错误:' + str(e))
        return False
コード例 #4
0
def putFTP(task, file):
    try:
        conn = MyFTP(task.target, int(task.port), str(task.finger))
        conn.Login(task.username, task.password)
        conn.ftp.cwd(task.dir.rstrip())
        path = file[5:]
        print(path)
        conn.UpLoadFile(file, path)
        conn.quit()
        return True
    except Exception as e:
        LOGR.error('FTP上传错误:' + str(e))
        return False