Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import re
  5. from ftplib import FTP
  6. # Need to install gitpython
  7. from git import Repo
  8.  
  9. # working directory
  10. cwd = os.getcwd()
  11. print '\033[92m'+'Git repository: {}'.format(cwd)
  12. print '\033[97m'
  13.  
  14. repo = Repo(cwd)
  15. hcommit = repo.head.commit
  16. files = []
  17.  
  18. ignore = open('ftpignore.lst')
  19. for idx in hcommit.diff(None):
  20. if not idx.a_path in ignore:
  21. files.append(idx.a_path)
  22.  
  23.  
  24.  
  25.  
  26. print files
  27. # read ftp config file
  28. myhost = {}
  29. config = open('ftpconfig.ini')
  30.  
  31. for line in config:
  32. key, value = line.split("=")
  33. myhost[key.strip()] = value.strip()
  34.  
  35. #print myhost
  36. ftp = FTP(myhost['server'])
  37. #ftp.set_debuglevel(1)
  38. ftp.login(myhost['user'],myhost['password'])
  39.  
  40. # list files in root
  41. #ftp.retrlines('LIST')
  42.  
  43. # change directory
  44. print '\033[95m'
  45. dirpath = myhost['folder']
  46. ftp.cwd(dirpath)
  47. #ftp.retrlines('LIST')
  48. for file in files:
  49. print 'Uploading: {}'.format(file)
  50. ftp.storbinary('STOR '+ file, open(file, 'rb'))
  51. ftp.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement