Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import argparse
  2. import sys
  3. import traceback
  4. import os
  5. import time
  6.  
  7. PATH = "???????"
  8. SERVER_PATH = "????????"
  9.  
  10. def upload(root, filename):
  11. filepath = os.path.join(root, filename)
  12. subpath = filepath[len(PATH):]
  13.  
  14. subpath = subpath.replace(" ", "\ ")
  15.  
  16. print("Server path: {}{}".format(
  17. SERVER_PATH,
  18. subpath
  19. ))
  20.  
  21. result = os.system('scp -l 4000 -i id_rsa {} ????@????:{}{}'.format(
  22. filepath,
  23. SERVER_PATH,
  24. subpath
  25. ))
  26.  
  27. print(result)
  28.  
  29. return result == 0
  30.  
  31.  
  32. if __name__ == "__main__":
  33. try:
  34. parser = argparse.ArgumentParser(prog="auto_upload_?????", description="Uploads all files from the specified folder to the specified folder over ftp")
  35. parser.add_argument("-v", "--verbose", help="Show debug informations", action="store_true")
  36. args = parser.parse_args()
  37.  
  38. running = True
  39. while running:
  40. for root, dirs, files in os.walk(PATH):
  41. for file in files:
  42. filepath = os.path.join(root, file)
  43.  
  44. print("Uploading {}".format(file))
  45.  
  46. if upload(root, file):
  47. print("Success. Removing {}".format(file))
  48. os.remove(filepath)
  49.  
  50. # Empty folders
  51. for folder in dirs:
  52. folderpath = os.path.join(root, folder)
  53. if os.listdir(folderpath) == "":
  54. print("Removing empty folder {}".format(folder))
  55. os.rmdir(folderpath)
  56.  
  57. print("Sleep 5 minutes...")
  58. time.sleep(300)
  59. except Exception as e:
  60. print(e)
  61. print(sys.exc_info()[0])
  62. print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement