Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import sys
  4. from ftplib import FTP_TLS
  5. import os
  6.  
  7. rls_name = sys.argv[1]
  8. rls_path = sys.argv[2]
  9. full_rls_path = os.path.join(rls_path, rls_name)
  10. section = rls_path.strip('/').split('/')[-1]
  11. ftp_path = '/_ARCHiVE/' + section
  12.  
  13. host = 'localhost'
  14. port = 24458
  15. username = 'w0rlock'
  16. password = 'bridge105'
  17.  
  18.  
  19. def file_exists(file_name):
  20.     ftp_listing = myFTP.mlsd()
  21.     for item, properties in ftp_listing:
  22.         if item == file_name and properties['type'] == 'file':
  23.             return True
  24.     else:
  25.         return False
  26.  
  27.  
  28. def folder_exists(folder_name):
  29.     ftp_listing = myFTP.mlsd()
  30.     for item, properties in ftp_listing:
  31.         if item == folder_name and properties['type'] == 'dir':
  32.             return True
  33.     else:
  34.          return False
  35.  
  36.  
  37. def uploadThis(path):
  38.     files = os.listdir(path)
  39.     os.chdir(path)
  40.    
  41.     for f in files:
  42.         if os.path.isfile(f):
  43.             if file_exists(f) is False:
  44.                 fh = open(f, 'rb')
  45.                 myFTP.storbinary('STOR %s' % f, fh)
  46.                 fh.close()
  47.         elif os.path.isdir(f):
  48.             if folder_exists(f) is False:
  49.                 myFTP.mkd(f)
  50.             myFTP.cwd(f)
  51.             uploadThis(f)
  52.     myFTP.cwd('..')
  53.     os.chdir('..')
  54.  
  55. if 'CONSOLE' in rls_path:
  56.     myFTP = FTP_TLS()
  57.     myFTP.connect(host, port)
  58.     myFTP.login(username, password)
  59.     myFTP.prot_p()
  60.     myFTP.cwd(ftp_path)
  61.     if folder_exists(rls_name) is False:
  62.         myFTP.mkd(rls_name)
  63.     myFTP.cwd(rls_name)
  64.     uploadThis(full_rls_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement