一套小型工作自动化系统。
使用语言:Python3.
主要功能:FTP下载、zip解压、文件重命名、Excle中执行vba宏、Excle数据合并。
FTP主要方法:(介绍项目用到的方法)
connect(ip, port):连接FTP服务器。
login(user, passwd):FTP登录。
cwd(path):进入FTP服务器的某个目录。(Come to Work Directory)
retrbinary(cmd, cb):执行ftp命令。
cmd:要执行的指令。
cb:callback。eg:open(file, "wb").write
quit():FTP退出。资源释放。
将ftp模块化封装,使用起来会更加方便。可以在hub下载相关代码:git@gitee.com:powerbinbin/auto_sys_dialy.git
FTP非常简单,直接上代码:
from ftplib import FTP
debug=False
class ftp():
def __init__(self):
if debug is True:
print("class-ftp init...")
self.ftp=FTP()
if debug is True:
print("class-ftp init done")
def login(self, user='binbin', passwd='Public1223', ip="192.168.0.103", port=5432, path=None):
if ip is None:
print("Login Err: ip shouldn't be None!")
exit(-1)
try:
self.ftp.connect(ip, port)
if debug is True:
print("class-ftp login: connect done")
except Exception as err:
print(err)
exit(-1)
try:
self.ftp.login(user, passwd)
if debug is True:
print("class-ftp login: login done")
except Exception as err:
print(err)
exit(-1)
try:
if path is not None:
self.ftp.cwd(path)
except Exception as err:
print(err)
exit(-1)
def download(self, file=None):
if debug is True:
print("class-ftp login: download...[%s]" %file)
if file is None:
print("download: file shouldn't be None!")
exit(-1)
try:
cb=open(file, "wb").write
cmd='RETR '+file
self.ftp.retrbinary(cmd, callback=cb)
except Exception as err:
print(err)
exit(-1)
if debug is True:
print("class-ftp login: download done [%s]" %file)
return file
def close(self):
self.ftp.quit()