File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,10 @@ def slimer_script():
22
22
23
23
backup_file .close ()
24
24
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 ()
Original file line number Diff line number Diff line change @@ -78,6 +78,26 @@ def get_the_latest_file_in_a_folder(path):
78
78
return max (paths , key = os .path .getctime )
79
79
80
80
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
+
81
101
def upload_file_to_server_ftp_without_logging_messages (file , filename , subdirectory ):
82
102
ftp = FTP (SEEDBOX_DOMAIN_NAME ) # connect to host, default port
83
103
try :
You can’t perform that action at this time.
0 commit comments