'''Created Jun 12, 2023 deeejas''' import ftplib import os import platform print(platform.python_version()) # FTP server details ftp_host = 'ftp.winmentor.ro' ftp_user = 'anonymous' ftp_password = None # 'password' # Mentor Phats mentor_file_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/versiune.txt' mentor_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/MENTOR.ZIP' efact_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/Tools_si_alte_EXE_de_module/Server_WMEfact/WMEFact_net10.zip' mentor_changelog_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/Modificari versiunea curenta.pdf' # Declaration Paths decl_file_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/versiune.txt' decl_zip_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/REMOTE/Declaratii_R.zip' decl_changelog_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/Modificari versiunea curenta.pdf' # Correction Paths corr_file_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/versiune.txt' corr_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/Mentor.zip' corr_changelog_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/Modificari versiunea curenta.pdf' # Local file path to save the downloaded files info tmp = 'tmp.txt' tmp_decl = 'tmp2.txt' tmp_corr = 'tmp3.txt' local_ment_path = 'versiune.txt' local_decl_path = 'versiune2.txt' local_corr_path = 'versiune3.txt' # Connect to the FTP server ftp = ftplib.FTP(ftp_host) ftp.login(ftp_user, ftp_password) def chk_mentor_version(): with open(local_ment_path, 'r') as cversion, open(tmp, 'wb') as ftp_version: ftp.retrbinary('RETR ' + mentor_file_path, ftp_version.write) lines = list(cversion.readlines())[0].strip()[-8:] with open(tmp, 'r') as ftp_version: slines = list(ftp_version.readlines())[0].strip()[-8:] print('your mentor version', lines) print('server mentor version', slines) download = input('do you want to download this version? ') if download == 'y': if not os.path.exists(slines): os.makedirs(slines) with open(f'{slines}/MENTOR.zip', 'wb') as mentor_zip: ftp.retrbinary('RETR ' + mentor_zip_path, mentor_zip.write) with open(f'{slines}/WMEFact_net10.zip', 'wb') as efact_zip: ftp.retrbinary('RETR ' + efact_zip_path, efact_zip.write) with open(f'{slines}/changelog.pdf', 'wb') as changelog: ftp.retrbinary('RETR ' + mentor_changelog_path, changelog.write) else: pass def chk_corr_version(): with open(local_corr_path, 'r') as cversion, open(tmp_corr, 'wb') as ftp_version: try: ftp.retrbinary('RETR ' + corr_file_path, ftp_version.write) lines = list(cversion.readlines())[0].strip()[-8:] except ftplib.error_perm: lines = 'no correction versions' try: with open(tmp_corr, 'r') as ftp_version: slines = list(ftp_version.readlines())[0].strip()[-8:] print('your correction version', lines) print('server correction version', slines) download = input('do you want to download this version? ') if download == 'y': if not os.path.exists(slines): os.makedirs(slines) with open(f'{slines}/Mentor.zip', 'wb') as corr_zip: ftp.retrbinary('RETR ' + corr_zip_path, corr_zip.write) with open(f'{slines}/changelog.pdf', 'wb') as changelog: ftp.retrbinary('RETR ' + corr_changelog_path, changelog.write) else: pass except IndexError: print('no correction versions') def chk_decl_version(): with open(local_decl_path, 'r') as cversion, open(tmp_decl, 'wb') as ftp_version: ftp.retrbinary('RETR ' + decl_file_path, ftp_version.write) lines = list(cversion.readlines())[0].strip()[-9:-1] with open(tmp_decl, 'r') as ftp_version: slines = list(ftp_version.readlines())[0].strip()[-9:-1] print('your decl version', lines) print('server decl version', slines) download = input('do you want to download this version? ') if download == 'y': if not os.path.exists(f'DECLARATII/{slines}'): os.makedirs(f'DECLARATII/{slines}') with open(f'DECLARATII/{slines}/declaratii_R.zip', 'wb') as decl_zip: ftp.retrbinary('RETR ' + decl_zip_path, decl_zip.write) with open(f'DECLARATII/{slines}/changelog.pdf', 'wb') as changelog: ftp.retrbinary('RETR ' + decl_changelog_path, changelog.write) else: pass def save_version(): save_versions = input('log the new versions? ') if save_versions == 'y': # Download the file with open(local_ment_path, 'wb') as local_file, open(local_decl_path, 'wb') as local_file2, open(local_corr_path, 'wb') as local_file3: ftp.retrbinary('RETR ' + mentor_file_path, local_file.write) ftp.retrbinary('RETR ' + decl_file_path, local_file2.write) try: ftp.retrbinary('RETR ' + corr_file_path, local_file3.write) except ftplib.error_perm: pass print('saved winmentor versions') else: print('nothing saved') if __name__ == '__main__': chk_mentor_version() chk_decl_version() chk_corr_version() save_version() ftp.quit()