filedepot-开源

  • G3_845459
    了解作者
  • 22.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 10:10
    上传日期
将文件备份和还原到Web邮件系统ftp,sftp。 使用gmail / hotmail等的免费存储空间。归档文件,分割大文件,加密和上传。 需要python(经过python 2.5测试)
filedepot-0.0.12.zip
  • filedepot-0.0.12
  • setup.py
    1.2KB
  • filedepot
  • src
  • fd_schedule.py
    1.2KB
  • __init__.py
    0B
  • fd_split.py
    3.9KB
  • fd_archive.py
    3.7KB
  • fd_interface.py
    11.9KB
  • fd_depository.py
    2.3KB
  • fd_ui_cmd.py
    5.6KB
  • fd_config.py
    6.3KB
  • fd_pickle.py
    235B
  • __init__.py
    0B
  • filedepot.py
    4.6KB
  • log
  • __init__.py
    0B
  • doc
  • image002.gif
    2.1KB
  • image001.gif
    1.1KB
  • manual.htm
    9KB
  • authors
    29B
  • PKG-INFO
    725B
  • README
    317B
  • todo
    457B
内容介绍
from __future__ import with_statement import os,datetime,smtplib import mimetypes,ftplib,poplib,email from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEAudio import MIMEAudio from email.MIMEImage import MIMEImage from email.Encoders import encode_base64 from fd_pickle import PickleMeToXML import fd_schedule import logging class baseinterface(PickleMeToXML): def __init__(self,user='',password='',server='',destination='',port=''): self.user = user self.password = password self.destination = destination self.server = server self.port = port self.name = "baseinterface" self.schedules = [] logging.info("interface added:\n%s",self.__str__(2)) def __str__(self, indent=0): ret = ' '*indent + " Type: %s\n"%self.name ret += ' '*indent + " User: %s\n"%self.user ret += ' '*indent + " Dest: %s\n"%self.destination ret += ' '*indent + " Server: %s\n"%self.server ret += ' '*indent + " Schedules:\n" for s in self.schedules: ret += s.__str__(indent+4) return ret def addSchedule(self,name, settings): if name == "day based": schedule = fd_schedule.daybased(days=settings["days"]) self.schedules.append(schedule) return schedule def isCompleteFileList(self, files): #Takes a list of files and checks that there is the right number and an END item. #ToDo: more of a sequential check count = len(files) if count == 1: logging.debug("Checking single file") if files[0][-3:] == 'END': return True else: return False else: logging.debug("Checking split files") for f in files: if f[-3:] == 'tmp': #assume incomplete file logging.debug("tmp file exists, assume incomplete") return False elif f[-4:] == '_END': logging.debug("Found END") if int(f[-7:-4]) == count: return True else: logging.debug("Count mismatch: file says %d, count says %d",int(f[-7:-4]),count ) return False logging.debug("Did not find END\n%s",files) return False def getArchiveList(self, arc,dirlist=[]): #Returns a dictionary of dates of lists that we have uploaded the archive via the interface final = {} for i in range(0,len(dirlist)): namestart = dirlist[i].find(arc.name+"_") if namestart != -1: name = dirlist[i][namestart:] namestart += len(arc.name)+1 datestr=dirlist[i][namestart:namestart+8] date = datetime.date(int(datestr[0:4]),int(datestr[4:6]),int(datestr[6:8])) if final.has_key(date) == False: final[date]=[] final[date].append(name) return final class ftp(baseinterface): def __init__(self,user='',password='',server='',destination='',port=21): super(ftp,self).__init__(user,password,server,destination,port) self.name = "ftp interface" def upload(self, arc, attachmentFilePaths): logging.info("Uploading to interface: %s",self.name) ftp = ftplib.FTP(self.server) ftp.login(self.user, self.password) ftp.cwd(self.destination) i=len(attachmentFilePaths) for attachmentFilePath in attachmentFilePaths: with open(attachmentFilePath,'rb') as f: if i == 1: basename = os.path.basename(attachmentFilePath) + "_END" else: basename = os.path.basename(attachmentFilePath) #Todo: Check for existing files -> previous failed attempts ftp.storbinary( "STOR %s" %(basename + "tmp"), f ) ftp.rename( basename+"tmp", basename) i-=1 ftp.quit() def getArchiveList(self, arc): #Returns a dictionary of dates of lists that we have uploaded the archive via the interface logging.debug("Get archive dir for interface: %s: %s",self.name,arc.name) f = ftplib.FTP(self.server) f.login(self.user, self.password) f.cwd(self.destination) dirlist = [] f.dir(dirlist.append) f.quit() return super(ftp,self).getArchiveList(arc,dirlist) def download(self, arc, files): #Downloads an archive logging.info("Get archives for interface: %s: %s",self.name,arc.name) ftp = ftplib.FTP(self.server) ftp.login(self.user, self.password) ftp.cwd(self.destination) downloaded = [] for f in files: if f[-4:] == '_END': final = f[:-4] else: final = f outfilename = os.path.join(arc.destdir, final) fileOut=open(outfilename,'wb') logging.info("Downloading: %s to: %s",f,outfilename) cmd = 'RETR '+ f ftp.retrbinary(cmd,fileOut.write) fileOut.close() downloaded.append(outfilename) logging.debug("Downloaded: %s",outfilename) ftp.quit() return downloaded class basemail(baseinterface): def __init__(self,user='',password='',server='',destination='',port=''): super(basemail,self).__init__(user,password,server,destination,port) self.name = "email interface" def encodeAttachment(self,attachmentFilePath): logging.info("Encoding into attachment: %s",attachmentFilePath) contentType, encoding = mimetypes.guess_type(attachmentFilePath) if contentType is None or encoding is not None: contentType = 'application/octet-stream' logging.debug("Attachment type: %s",contentType) mainType, subType = contentType.split('/', 1) file = open(attachmentFilePath, 'rb') if mainType == 'text': attachment = MIMEText(file.read()) elif mainType == 'message': attachment = email.message_from_file(file) elif mainType == 'image': attachment = MIMEImage(file.read(),_subType=subType) elif mainType == 'audio': attachment = MIMEAudio(file.read(),_subType=subType) else: attachment = MIMEBase(mainType, subType) attachment.set_payload(file.read()) encode_base64(attachment) file.close() attachment.add_header('Content-Disposition', 'attachment', filename=os.path.basename(attachmentFilePath)) return attachment def sendMailSMTP(self,subject, text, attachmentFilePaths, count = 0): max_size = 500000 logging.info("Sending mail - Subject: %s",subject) msg = MIMEMultipart() msg['From'] = self.user msg['To'] = self.destination msg.attach(MIMEText(text)) print self.user,self.destination,self.server,self.port,subject,text,attachmentFilePaths current_size = 0 while len(attachmentFilePaths) > 0: attachmentFilePath = attachmentFilePaths[0] msg.attach(self.encodeAttachment(attachmentFilePath)) attachmentFilePaths.remove(attachmentFilePaths[0]) current_size += os.path.getsize(attachmentFilePath) if current_size > max_size: break; if len(attachmentFilePaths) > 0: more_to_come = True final_subject = subject + "_%03d"%(count+1) else: more_to_come = False
评论
    相关推荐
    • ftp客户端源码
      (1)实现一个图形用户界面的FTP客户端,保证文件的安全传输和存储。 (2)提供登录界面,上传下载界面、帮助界面、关于界面 (3)通过输入服务器地址、用户名和密码,可以实现远程FTP主机的登录。 (4)提供本地...
    • FlashFXP FTP
      FlashFXP是强大、使用量广泛的FTP客户端,在经过了长久的测试后终于迎来了FlashFXP简体中文正式版。你可以使用FlashFXP 来发布和维护你的网站、上传下载基于FTP的文件、转移或者备份远程文件、与朋友远程分享文件等...
    • lrg-ftp:包含LRG元数据的存储
      lrg-ftp:包含LRG元数据的存储
    • ftp下载
      ftp下载
    • ftpserver
      可用于FTP服务器的搭建,简单方便,功能比较全面
    • ftp软件上传网站
      优质的网站上传工具,用着方便,占用存储少,欢迎大家下载。
    • FTP RFC959中文文档
      FTP 的目标是提高文件的共享性,提供非直接使用远程计算机,使存储介质对用 户透明和可 靠高效地传送数据。虽然我们也可以手工使用它,但是它的主要作用是供程序使 用的。在 阅读本文之前最好能够阅读TCP 协议标准...
    • FTPserver文件服务器
      FTP服务器(File Transfer Protocol Server)是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务。 FTP是File Transfer Protocol(文件传输协议)。顾名思义,就是专门用来传输文件的协议。简单地...
    • ftp 安装包
      ftp安装包可用于对文件的上传或下载到服务器,方便开发的文件传输。
    • FTP服务端
      发上来,希望能帮助到人,下次我也想得到帮助