Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys
- from ftplib import FTP_TLS
- import os
- rls_name = sys.argv[1]
- rls_path = sys.argv[2]
- full_rls_path = os.path.join(rls_path, rls_name)
- section = rls_path.strip('/').split('/')[-1]
- ftp_path = '/_ARCHiVE/' + section
- host = 'localhost'
- port = 24458
- username = 'w0rlock'
- password = 'bridge105'
- def file_exists(file_name):
- ftp_listing = myFTP.mlsd()
- for item, properties in ftp_listing:
- if item == file_name and properties['type'] == 'file':
- return True
- else:
- return False
- def folder_exists(folder_name):
- ftp_listing = myFTP.mlsd()
- for item, properties in ftp_listing:
- if item == folder_name and properties['type'] == 'dir':
- return True
- else:
- return False
- def uploadThis(path):
- files = os.listdir(path)
- os.chdir(path)
- for f in files:
- if os.path.isfile(f):
- if file_exists(f) is False:
- fh = open(f, 'rb')
- myFTP.storbinary('STOR %s' % f, fh)
- fh.close()
- elif os.path.isdir(f):
- if folder_exists(f) is False:
- myFTP.mkd(f)
- myFTP.cwd(f)
- uploadThis(f)
- myFTP.cwd('..')
- os.chdir('..')
- if 'CONSOLE' in rls_path:
- myFTP = FTP_TLS()
- myFTP.connect(host, port)
- myFTP.login(username, password)
- myFTP.prot_p()
- myFTP.cwd(ftp_path)
- if folder_exists(rls_name) is False:
- myFTP.mkd(rls_name)
- myFTP.cwd(rls_name)
- uploadThis(full_rls_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement