Skip to content

Commit a3aaf5a

Browse files
backup file upload done
1 parent 7456a91 commit a3aaf5a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

slimer_script.py

+7
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ def slimer_script():
2222

2323
backup_file.close()
2424
logging.info("All paths have been scanned. The backup file is saved")
25+
26+
# opens the file for reading only in binary format in order to upload
27+
file = open(backup_file.name, "rb")
28+
29+
upload_file_to_server_ftp(file, file.name)
30+
31+
file.close()

utilities.py

+20
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ def get_the_latest_file_in_a_folder(path):
7878
return max(paths, key=os.path.getctime)
7979

8080

81+
def upload_file_to_server_ftp(file, filename):
82+
ftp = FTP(SEEDBOX_DOMAIN_NAME) # connect to host, default port
83+
try:
84+
logging.info("trying to connect the ftp server...")
85+
ftp.login(user=SEEDBOX_USER_NAME, passwd=SEEDBOX_PASSWD) # login with credentials
86+
logging.info('ftp connection succeed !')
87+
try:
88+
# TODO : se placer dans le bon repertoire (ok) du serveur et
89+
# creer un dossier *nom application* s'il n'existe pas
90+
ftp.cwd(SEEDBOX_ROOT_SLIMER_SCRIPT_PATH) # Set the current directory on the server
91+
logging.info('sending ' + filename + ' file to the ftp server...')
92+
ftp.storbinary('STOR ' + filename + '', file) # uploading file to the server
93+
logging.info(filename + ' uploaded successfully!')
94+
except ftplib.all_errors:
95+
logging.error('unable to make directories')
96+
except ftplib.all_errors:
97+
logging.error('unable to connect to ftp server')
98+
ftp.quit()
99+
100+
81101
def upload_file_to_server_ftp_without_logging_messages(file, filename, subdirectory):
82102
ftp = FTP(SEEDBOX_DOMAIN_NAME) # connect to host, default port
83103
try:

0 commit comments

Comments
 (0)