Notepad++Good Luck To You!

python从ftp下载xlsx并提取指定列写text

#!/usr/bin/python

# -*- coding: UTF-8 -*-

 

import pandas as pd

import time

import os

from ftplib import FTP



#下载文件

def downfile(host,port,username,password,localpath,remotepath,filename):

    ftp = FTP()

    ftp.connect(host,port)

    ftp.set_debuglevel(0)  # 2显示详细信息

    ftp.login(username,password)

    print(ftp.welcome)

    os.chdir(localpath) 

    ftp.cwd(remotepath)

    ftp.nlst() 

    file_handle = open(filename,"wb").write

    ftp.retrbinary('RETR %s' % os.path.basename(filename),file_handle,blocksize=1024)

    #ftp.delete(filename)

    ftp.set_debuglevel(0)

    ftp.quit()

    

#处理文件 

def handlerfile(inputfile,outputfile):

    out_f = open(outputfile, "w")

    #读取指定列

    df = pd.read_excel(inputfile, usecols=[10,23,34,35])


    data = df.values.tolist()

    result=[]

    for li in data:

        str=','.join(li)

        result.append(str)        

    out_f.write('\n'.join(result))

    out_f.close() 

    

  

def job():

    print('任务开始:', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))

    downfile(host='192.168.0.63',port=21,username='1',password='1',localpath='./',remotepath='/',filename='a.xlsx')

    handlerfile(inputfile='./a.xlsx',outputfile='./a.txt')

    print('任务结束:', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))

 

job()


«    2023年7月    »
12
3456789
10111213141516
17181920212223
24252627282930
31
TOP 搜索
TOP 控制面板
您好,欢迎到访网站!
  查看权限
TOP 最新留言
    TOP 作者列表
    TOP 站点信息
    • 文章总数:163
    • 页面总数:0
    • 分类总数:6
    • 标签总数:20
    • 评论总数:0
    • 浏览总数:312004
    召唤伊斯特瓦尔