#-*-encoding:gbk-*-
#Author:没车步行
#Email:lu_zhouyu@hotmail.com
#Edit:2009-4-7
#Copyright:转载请注明出处
import sys
import base64
import shelve
import myftplib
import os
shlfp='task.dat'
class mytask:
"""
shlf:任务队列
remoteip:远程服务器IP,默认localhost
remoteport:远程服务器端口,默认21
remotepath:远程服务器路径,默认根目录
remotefilename:远程服务器文件,必填项
localpath:本地路径,默认程序目录
localfilename:本地文件,默认同远程服务器文件
taskcode:任务代码,用于判断任务是否已存在,假设性条件无限制
loginname:远程服务器登录名
loginpassword:远程服务器登录密码
"""
shlf=shelve.open(shlfp)
remoteip='localhost'
remoteport='21'
remotepath=localpath=''
localfilename=remotefilename=''
taskcode=''
loginname=''
loginpassword=''
def __init__(self):
self.printtask()
def maketask(self,remotefilename,localfilename,**kwargs):
self.remotefilename=remotefilename
if localfilename:
self.localfilename=localfilename
else:
self.localfilename=remotefilename
for k in kwargs.keys():
v=kwargs[k]
if k=='remoteip' and v!='':
self.remoteip=v
elif k=='remoteport' and v!='':
self.remoteport=v
elif k=='remotepath' and v!='':
self.remotepath=v
elif k=='localpath' and v!='':
self.localpath=v
elif k=='loginname' and v!='':
self.loginname=v
elif k=='loginpassword' and v!='':
self.loginpassword=v
self.starttask()
def removetask(self,taskid):
del self.shlf[taskid]
def starttask(self):
taskid='1'
if len(self.shlf):
taskid=str(int(max(self.shlf.keys()))+1)
taskval={}
taskval['remoteip']=self.remoteip
taskval['remoteport']=self.remoteport
taskval['remotepath']=self.remotepath
taskval['remotefilename']=self.remotefilename
taskval['localpath']=self.localpath
taskval['localfilename']=self.localfilename
taskval['taskcode']=self.taskcode
taskval['loginname']=self.loginname
taskval['loginpassword']=self.loginpassword
self.shlf[taskid]=taskval
myftplib.mywork(self.remoteip,self.remoteport,self.remotepath,self.remotefilename,self.localpath,self.localfilename,self.loginname,self.loginpassword,0)
del self.shlf[taskid]
self.shlf.close()
def restarttask(self,taskid):
taskval=self.shlf[taskid]
remoteip=taskval['remoteip']
remoteport=taskval['remoteport']
remotepath=taskval['remotepath']
remotefilename=taskval['remotefilename']
localpath=taskval['localpath']
localfilename=taskval['localfilename']
loginname=taskval['loginname']
loginpassword=taskval['loginpassword']
myftplib.mywork(remoteip,remoteport,remotepath,remotefilename,localpath,localfilename,loginname,loginpassword,1)
del self.shlf[taskid]
self.shlf.close()
def printtask(self):
print '%-6s|%-15s|%s'%('任务ID','服务器地址','下载文件名')
print '%s'%('-'*38)
for t in self.shlf.keys():
v=self.shlf[t]
print '%-6s|%-15s|%s'%(t,v['remoteip'],v['remotefilename'])
print ''
if __name__=='__main__':
mytask=mytask()
if len(mytask.shlf):
chk=raw_input('重新启动已存在的下载任务(Y-是/N-否):')
if chk.strip().upper()=='Y':
while 1:
tid=raw_input('输入任务ID:')
tid=tid.strip()
if mytask.shlf.has_key(tid):
mytask.restarttask(tid)
break
print '输入有误!',
sys.exit()
remoteip=raw_input("远程地址(localhost):")
remoteip=remoteip.strip()
remoteport=raw_input("远程端口(21):")
remoteport=remoteport.strip()
remotepath=raw_input("远程路径(默认为根目录):")
remotepath=remotepath.strip()
remotefilename=raw_input("远程文件名:")
remotefilename=remotefilename.strip()
loginname=raw_input("登录名:")
loginname=loginname.strip()
loginpassword=raw_input("登录密码:")
loginpassword=loginpassword.strip()
localfilename=raw_input("本地重命名(默认与远程文件同名):")
localfilename=localfilename.strip()
localpath=raw_input("本地路径(不存在自动创建):")
localpath=localpath.strip()
mytask.maketask(remotefilename,\
localfilename,\
remoteip=remoteip,\
remoteport=remoteport,\
remotepath=remotepath,\
localpath=localpath,\
loginname=loginname,\
loginpassword=loginpassword)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
码农陆蜀黍
- 粉丝: 1
- 资源: 2
最新资源
- Python-Python资源
- SQLite.swift-Swift资源
- 10位高分辨率SAR ADC的100MHz应用-采用TSMC28nm工艺库实现高效率性能 ,基于TSMC28工艺库的10bit高分辨率,高达每秒百万次采样率的ADC转换器技术解析,10bit 100
- SpireCV-机器人开发资源
- 基于Vue的网易云音乐uniapp小程序设计源码
- 基于Python及前端技术的meiduo_project电商系统设计源码
- 四轮转向汽车Carsim与Simulink联合仿真滑模控制模型:研究驾驶行为及车辆动力学性能的综合分析文献集合,四轮转向汽车Carsim-Simulink联合仿真滑模控制模型详解:包含驾驶员模型、二自
- 基于C++语言的整数分解算法设计源码
- MXVideo-Kotlin资源
- jppe-rs-Rust资源
- 基于Maxwell模型的80至355极永磁同步电动机设计:高效率、可调速、可定制的电磁方案与冲片图纸,三相调速永磁同步电动机的高效Maxwell模型与优化电磁设计方案,三相调速永磁同步电动机maxwe
- smart-mqtt-硬件开发资源
- 三菱电梯凌云pro地址码详解:涵盖各类部件地址码及MTS-2软件功能介绍,三菱电梯凌云pro地址码详解:涵盖基本与附加功能部件超过百项,专业软件MTS-2-V1.6.1及注册机支持,三菱电梯凌云pro
- 晶振频率测量与保护模块:高稳定性、隔离设计、多功能测量与保护一体化解决方案,晶振频率精确测量模块:电源隔离、输出可适配多款仪器的稳定测频助手,集成过流与过压保护功能,晶振频率测量模块,晶振是很容易受到
- gallery-移动应用开发资源
- elab-单片机开发资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)