Advertisement
Ceron

backup.py - ICS backuper

Aug 22nd, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. """
  2. This script creates a daily backup
  3. of ICS files on an FTP server.
  4. The backups are stored local and on backups-dir on
  5. ftp server :)
  6. """
  7. from ftplib import FTP
  8. from datetime import date
  9. class FTPMan():
  10.     def __init__(self, bla):
  11.         self.ftp = FTP(bla)
  12.     def login(self, user, pwd):
  13.         self.ftp.login(user, pwd)
  14.     def CWD(self, dir):
  15.         self.ftp.cwd(dir)
  16.     def download(self, file, targetFile):
  17.         self.ftp.retrbinary('RETR ' + file, open(targetFile,"wb").write)
  18.     def upload(self, targetFile, localfile):
  19.         self.ftp.storbinary('STOR ' + targetFile, localfile)
  20.     def dc(self):
  21.         self.ftp.quit()
  22.  
  23. def main():
  24.     backupname = 'allgemein-' + str(date.today().day) + '-' + str(date.today().month) + '-' + str(date.today().year) + '.ics'
  25.     man = FTPMan('ftp-serveradress.com')
  26.     man.login('username','password')
  27.     man.CWD('Kalender')
  28.     man.download('allgemein.ics',backupname)
  29.     man.CWD('backups')
  30.     f = open(backupname,"rb")
  31.     man.upload(backupname, f)
  32.     man.dc()
  33.    
  34.  
  35. if __name__ == "__main__":
  36.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement