#!/usr/bin/python#-*-coding:UTF-8-*-importpandasaspdimporttimeimportosfromftplibimportFTP#下载文件defdownfile(host,port,username,...
#!/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()
全文详见:http://xpxw.com/?id=146