Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import sys
- import traceback
- import os
- import time
- PATH = "???????"
- SERVER_PATH = "????????"
- def upload(root, filename):
- filepath = os.path.join(root, filename)
- subpath = filepath[len(PATH):]
- subpath = subpath.replace(" ", "\ ")
- print("Server path: {}{}".format(
- SERVER_PATH,
- subpath
- ))
- result = os.system('scp -l 4000 -i id_rsa {} ????@????:{}{}'.format(
- filepath,
- SERVER_PATH,
- subpath
- ))
- print(result)
- return result == 0
- if __name__ == "__main__":
- try:
- parser = argparse.ArgumentParser(prog="auto_upload_?????", description="Uploads all files from the specified folder to the specified folder over ftp")
- parser.add_argument("-v", "--verbose", help="Show debug informations", action="store_true")
- args = parser.parse_args()
- running = True
- while running:
- for root, dirs, files in os.walk(PATH):
- for file in files:
- filepath = os.path.join(root, file)
- print("Uploading {}".format(file))
- if upload(root, file):
- print("Success. Removing {}".format(file))
- os.remove(filepath)
- # Empty folders
- for folder in dirs:
- folderpath = os.path.join(root, folder)
- if os.listdir(folderpath) == "":
- print("Removing empty folder {}".format(folder))
- os.rmdir(folderpath)
- print("Sleep 5 minutes...")
- time.sleep(300)
- except Exception as e:
- print(e)
- print(sys.exc_info()[0])
- print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement